fix hanging goroutine

This commit is contained in:
2024-01-26 16:27:16 +08:00
parent 03539164e5
commit 86f4adca3f

View File

@ -119,7 +119,12 @@ func (signalingServer SignalingServer) handleRedisPubSub(ctx context.Context, na
} }
ch := pubsub.Channel() ch := pubsub.Channel()
for msg := range ch { for {
select {
case <-ctx.Done():
return nil
case msg := <-ch:
switch msg.Channel { switch msg.Channel {
case signalingServer.redisKeyPrefix + ":" + room + ":discover": case signalingServer.redisKeyPrefix + ":" + room + ":discover":
if err := stream.Send(&proto.SignalingMessage{ if err := stream.Send(&proto.SignalingMessage{
@ -175,6 +180,7 @@ func (signalingServer SignalingServer) handleRedisPubSub(ctx context.Context, na
} }
} }
} }
}
return nil return nil
} }