conditionally block on signal relay close (#1722)

This commit is contained in:
Paul Wells
2023-05-18 13:53:20 -07:00
committed by GitHub
parent e03b7ef8de
commit 5f3ea75a1e
+13 -14
View File
@@ -104,6 +104,7 @@ func (r *signalClient) StartParticipantSignal(
Config: r.config, Config: r.config,
Writer: signalRequestMessageWriter{}, Writer: signalRequestMessageWriter{},
CloseOnFailure: true, CloseOnFailure: true,
BlockOnClose: true,
}) })
resChan := NewDefaultMessageChannel() resChan := NewDefaultMessageChannel()
@@ -228,6 +229,7 @@ type SignalSinkParams[SendType, RecvType RelaySignalMessage] struct {
Config config.SignalRelayConfig Config config.SignalRelayConfig
Writer SignalMessageWriter[SendType] Writer SignalMessageWriter[SendType]
CloseOnFailure bool CloseOnFailure bool
BlockOnClose bool
} }
func NewSignalMessageSink[SendType, RecvType RelaySignalMessage](params SignalSinkParams[SendType, RecvType]) MessageSink { func NewSignalMessageSink[SendType, RecvType RelaySignalMessage](params SignalSinkParams[SendType, RecvType]) MessageSink {
@@ -255,22 +257,19 @@ func (s *signalMessageSink[SendType, RecvType]) Close() {
} }
s.mu.Unlock() s.mu.Unlock()
// NOTE: not waiting for stream context to be done. // conditionally block while closing to wait for outgoing messages to drain
// Waiting for stream context to be done is confirmation
// that the close message has been processed by the other side.
// In ideal conditions, waiting for it is a clean end.
// //
// But, in cases where the remote side goes away abruptly, waiting // on media the signal sink shares a goroutine with other signal connection
// for stream context to be done could block connection progress // attempts from the same participant so blocking delays establishing new
// till the timeout hits. // sessions during reconnect.
// //
// The abrupt case happens when one side of the signal // on controller closing without waiting for the outstanding messages to
// relay is shut down due to scale down or a crash. // drain causes leave messages to be dropped from the write queue. when
// // this happens other participants in the room aren't notified about the
// Uncomment the following line to wait for close acknowledgement, // departure until the participant times out.
// but the system should be able to wait long enough (till timeout) if s.BlockOnClose {
// without adverse impact if waiting for close acknowledgement. <-s.Stream.Context().Done()
//<-s.Stream.Context().Done() }
} }
func (s *signalMessageSink[SendType, RecvType]) IsClosed() bool { func (s *signalMessageSink[SendType, RecvType]) IsClosed() bool {