Skip to content

Commit de2a2a0

Browse files
committed
Close session channels on DELETE to avoid goroutine leaks
1 parent f3dbeb0 commit de2a2a0

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

server/streamable_http.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -929,9 +929,14 @@ func (s *StreamableHTTPServer) handleDelete(w http.ResponseWriter, r *http.Reque
929929
return
930930
}
931931

932-
// Unregister the session
932+
// Unregister and fully clean-up the session
933+
if sessVal, ok := s.sessions.Load(sessionID); ok {
934+
if httpSess, ok := sessVal.(*streamableHTTPSession); ok {
935+
close(httpSess.notificationChannel) // unblock the forwarding goroutine
936+
}
937+
s.sessions.Delete(sessionID)
938+
}
933939
s.server.UnregisterSession(r.Context(), sessionID)
934-
s.sessions.Delete(sessionID)
935940

936941
// Return 200 OK
937942
w.WriteHeader(http.StatusOK)

0 commit comments

Comments
 (0)