Close web socket connections in all paths. (#4747)

* Close web socket connections in all paths.

There was a leak of WebSocket pingWorker if the initial response write
errored as it did not close the WebSocket connection.

* graceful close
This commit is contained in:
Raja Subramanian
2026-08-12 15:15:38 +05:30
committed by GitHub
parent c432e49c1e
commit 35fe831f1d
3 changed files with 22 additions and 8 deletions
+2 -3
View File
@@ -467,6 +467,7 @@ func (s *RTCService) serve(w http.ResponseWriter, r *http.Request, needsJoinRequ
// websocket established
sigConn := NewWSSignalConnection(conn, s.limits.SignalMessageSizeLimit)
defer sigConn.CloseWithReason("")
pLogger.Debugw("sending initial response", "response", logger.Proto(initialResponse))
count, err := sigConn.WriteResponse(initialResponse)
if err != nil {
@@ -495,9 +496,7 @@ func (s *RTCService) serve(w http.ResponseWriter, r *http.Request, needsJoinRequ
defer func() {
// when the source is terminated, this means Participant.Close had been called and RTC connection is done
// we would terminate the signal connection as well
closeMsg := websocket.FormatCloseMessage(websocket.CloseNormalClosure, "")
_ = conn.WriteControl(websocket.CloseMessage, closeMsg, time.Now().Add(time.Second))
_ = conn.Close()
sigConn.CloseWithReason("")
}()
defer func() {
if r := rtc.Recover(pLogger); r != nil {