fix: various locks in the signaler
This commit is contained in:
@@ -83,7 +83,8 @@ func main() {
|
|||||||
// Wait for a session request
|
// Wait for a session request
|
||||||
session, err := client.PopSession(ctx, withAuth(token, &pb.PopSessionRequest{}))
|
session, err := client.PopSession(ctx, withAuth(token, &pb.PopSessionRequest{}))
|
||||||
if err != nil {
|
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
|
// try getting a new token
|
||||||
token, err = getAuthToken(ctx, client, cfg)
|
token, err = getAuthToken(ctx, client, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -91,7 +92,10 @@ func main() {
|
|||||||
}
|
}
|
||||||
continue
|
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
|
continue
|
||||||
}
|
}
|
||||||
go handleSession(ctx, client, token, session, vid)
|
go handleSession(ctx, client, token, session, vid)
|
||||||
|
|||||||
Binary file not shown.
@@ -130,6 +130,7 @@ func (s *Server) CreateAuthToken(ctx context.Context, request *connect.Request[p
|
|||||||
return nil, fmt.Errorf("error creating UUID: %v", err)
|
return nil, fmt.Errorf("error creating UUID: %v", err)
|
||||||
}
|
}
|
||||||
id = myUUID.String()
|
id = myUUID.String()
|
||||||
|
s.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
token := &internalpb.AuthToken{
|
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
|
// 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.
|
// 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) {
|
func (s *Server) CreateSession(ctx context.Context, request *connect.Request[pb.CreateSessionRequest]) (*connect.Response[pb.Session], error) {
|
||||||
|
|
||||||
log.Printf("Creating session")
|
log.Printf("Creating session")
|
||||||
defer log.Printf("Done session")
|
defer log.Printf("Done session")
|
||||||
thisSession := request.Msg.Session
|
thisSession := request.Msg.Session
|
||||||
@@ -224,14 +224,14 @@ func (s *Server) PopSession(ctx context.Context, request *connect.Request[pb.Pop
|
|||||||
s.mu.Unlock()
|
s.mu.Unlock()
|
||||||
|
|
||||||
var sess *session
|
var sess *session
|
||||||
tick := time.NewTicker(time.Second * 30)
|
tick := time.NewTicker(time.Second * 20)
|
||||||
defer tick.Stop()
|
defer tick.Stop()
|
||||||
select {
|
select {
|
||||||
case sess = <-ch:
|
case sess = <-ch:
|
||||||
// OK
|
// OK
|
||||||
case <-tick.C:
|
case <-tick.C:
|
||||||
// have them retry
|
// have them retry
|
||||||
return nil, connect.NewError(connect.CodeDeadlineExceeded, fmt.Errorf("try again"))
|
return connect.NewResponse(&pb.Session{}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if sess == nil {
|
if sess == nil {
|
||||||
@@ -253,17 +253,19 @@ func (s *Server) CreateIceMessage(ctx context.Context, request *connect.Request[
|
|||||||
req := request.Msg
|
req := request.Msg
|
||||||
|
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
|
||||||
|
|
||||||
session, ok := s.sessionsById[req.GetSessionIdentifier().GetId()]
|
session, ok := s.sessionsById[req.GetSessionIdentifier().GetId()]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
s.mu.Unlock()
|
||||||
return nil, status.Errorf(codes.NotFound, "unknown session")
|
return nil, status.Errorf(codes.NotFound, "unknown session")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := s.camerasByHome[authToken.Home]; !ok {
|
if _, ok := s.camerasByHome[authToken.Home]; !ok {
|
||||||
|
s.mu.Unlock()
|
||||||
return nil, status.Errorf(codes.NotFound, "home %q not found", authToken.Home)
|
return nil, status.Errorf(codes.NotFound, "home %q not found", authToken.Home)
|
||||||
}
|
}
|
||||||
_, isCamera := s.camerasByHome[authToken.Home][authToken.Uid]
|
_, isCamera := s.camerasByHome[authToken.Home][authToken.Uid]
|
||||||
|
s.mu.Unlock()
|
||||||
|
|
||||||
session.createTime = time.Now()
|
session.createTime = time.Now()
|
||||||
msg := req.GetIceMessage()
|
msg := req.GetIceMessage()
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ spec:
|
|||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: signaler
|
- 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:
|
command:
|
||||||
- /signaler
|
- /signaler
|
||||||
ports:
|
ports:
|
||||||
|
|||||||
Reference in New Issue
Block a user