leave signal context open after stream closes (#1887)

This commit is contained in:
Paul Wells
2023-07-16 20:24:11 -07:00
committed by GitHub
parent 5d1d454a98
commit 9f3c975b1c
+5 -14
View File
@@ -133,17 +133,6 @@ func (r *signalService) RelaySignal(stream psrpc.ServerStream[*rpc.RelaySignalRe
"connID", ss.ConnectionId,
)
// copy the context to prevent a race between the session handler closing
// and the delivery of any parting messages from the client. take care to
// copy the incoming rpc headers to avoid dropping any session vars.
ctx, cancel := context.WithCancel(metadata.NewContextWithIncomingHeader(context.Background(), metadata.IncomingHeader(stream.Context())))
// wait until room setup finishes to cancel the session context even if the
// stream has closed. this is required to complete setup i/o after room api
// has discarded the temp client.
sessionHandlerDone := make(chan struct{})
defer close(sessionHandlerDone)
sink := routing.NewSignalMessageSink(routing.SignalSinkParams[*rpc.RelaySignalResponse, *rpc.RelaySignalRequest]{
Logger: l,
Stream: stream,
@@ -163,11 +152,13 @@ func (r *signalService) RelaySignal(stream psrpc.ServerStream[*rpc.RelaySignalRe
l.Infow("signal stream closed", "error", err)
reqChan.Close()
<-sessionHandlerDone
cancel()
}()
// copy the context to prevent a race between the session handler closing
// and the delivery of any parting messages from the client. take care to
// copy the incoming rpc headers to avoid dropping any session vars.
ctx := metadata.NewContextWithIncomingHeader(context.Background(), metadata.IncomingHeader(stream.Context()))
err = r.sessionHandler(ctx, livekit.RoomName(ss.RoomName), *pi, livekit.ConnectionID(ss.ConnectionId), reqChan, sink)
if err != nil {
l.Errorw("could not handle new participant", err)