diff --git a/cmd/watcher/watcher.go b/cmd/watcher/watcher.go index 4483310..c0cc769 100644 --- a/cmd/watcher/watcher.go +++ b/cmd/watcher/watcher.go @@ -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) diff --git a/dbuild/usr/local/bin/watcher b/dbuild/usr/local/bin/watcher index c0b3775..0481d24 100755 Binary files a/dbuild/usr/local/bin/watcher and b/dbuild/usr/local/bin/watcher differ diff --git a/pkg/signaler/signaler.go b/pkg/signaler/signaler.go index e1f70d2..f71e17b 100644 --- a/pkg/signaler/signaler.go +++ b/pkg/signaler/signaler.go @@ -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() diff --git a/prod.yaml b/prod.yaml index 9850287..8af3c93 100644 --- a/prod.yaml +++ b/prod.yaml @@ -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: