Skip to content

Commit 07f173e

Browse files
authored
SSE example: Fix server blocking on client channel (#173)
1 parent e8d3a6a commit 07f173e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

server-sent-event/main.go

+5
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ func (stream *Event) serveHTTP() gin.HandlerFunc {
126126
stream.NewClients <- clientChan
127127

128128
defer func() {
129+
// Drain client channel so that it does not block. Server may keep sending messages to this channel
130+
go func() {
131+
for range clientChan {
132+
}
133+
}()
129134
// Send closed connection to event server
130135
stream.ClosedClients <- clientChan
131136
}()

0 commit comments

Comments
 (0)