fix: various locks in the signaler

This commit is contained in:
Charles
2024-01-15 23:12:13 -08:00
parent 195cd67c90
commit 6851b30ad8
4 changed files with 13 additions and 7 deletions
+6 -2
View File
@@ -83,7 +83,8 @@ func main() {
// Wait for a session request
session, err := client.PopSession(ctx, withAuth(token, &pb.PopSessionRequest{}))
if err != nil {
if s, ok := status.FromError(err); ok && s.Code() == codes.NotFound {
code, hasCode := status.FromError(err)
if hasCode && code.Code() == codes.NotFound {
// try getting a new token
token, err = getAuthToken(ctx, client, cfg)
if err != nil {
@@ -91,7 +92,10 @@ func main() {
}
continue
}
log.Error().Err(err).Msg("error creating session")
log.Error().Err(err).Str("code", fmt.Sprintf("code %d", code.Code())).Bool("has code", hasCode).Msg("error creating session")
continue
}
if session.Msg.GetId() == nil {
continue
}
go handleSession(ctx, client, token, session, vid)
Binary file not shown.
+6 -4
View File
@@ -130,6 +130,7 @@ func (s *Server) CreateAuthToken(ctx context.Context, request *connect.Request[p
return nil, fmt.Errorf("error creating UUID: %v", err)
}
id = myUUID.String()
s.mu.Unlock()
}
token := &internalpb.AuthToken{
@@ -169,7 +170,6 @@ func (s *Server) ListCameras(ctx context.Context, request *connect.Request[pb.Li
// Optionally, wait_for_update can be set to prevent returning until the Camera has seen the
// session request, populated candidates, and returned a session offer.
func (s *Server) CreateSession(ctx context.Context, request *connect.Request[pb.CreateSessionRequest]) (*connect.Response[pb.Session], error) {
log.Printf("Creating session")
defer log.Printf("Done session")
thisSession := request.Msg.Session
@@ -224,14 +224,14 @@ func (s *Server) PopSession(ctx context.Context, request *connect.Request[pb.Pop
s.mu.Unlock()
var sess *session
tick := time.NewTicker(time.Second * 30)
tick := time.NewTicker(time.Second * 20)
defer tick.Stop()
select {
case sess = <-ch:
// OK
case <-tick.C:
// have them retry
return nil, connect.NewError(connect.CodeDeadlineExceeded, fmt.Errorf("try again"))
return connect.NewResponse(&pb.Session{}), nil
}
if sess == nil {
@@ -253,17 +253,19 @@ func (s *Server) CreateIceMessage(ctx context.Context, request *connect.Request[
req := request.Msg
s.mu.Lock()
defer s.mu.Unlock()
session, ok := s.sessionsById[req.GetSessionIdentifier().GetId()]
if !ok {
s.mu.Unlock()
return nil, status.Errorf(codes.NotFound, "unknown session")
}
if _, ok := s.camerasByHome[authToken.Home]; !ok {
s.mu.Unlock()
return nil, status.Errorf(codes.NotFound, "home %q not found", authToken.Home)
}
_, isCamera := s.camerasByHome[authToken.Home][authToken.Uid]
s.mu.Unlock()
session.createTime = time.Now()
msg := req.GetIceMessage()
+1 -1
View File
@@ -17,7 +17,7 @@ spec:
spec:
containers:
- name: signaler
image: us-central1-docker.pkg.dev/home-sensors-400805/signaler/image:20240110-2245
image: us-central1-docker.pkg.dev/home-sensors-400805/signaler/image:20240115-2309
command:
- /signaler
ports: