File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed
Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ func newWebsocketPump(
4141 frontend : frontend ,
4242 backend : backend ,
4343 logger : logger ,
44- done : make (chan struct {}),
44+ done : make (chan struct {}, 1 ),
4545 }
4646}
4747
@@ -93,10 +93,19 @@ func (p *websocketPump) run() error {
9393}
9494
9595func (p * websocketPump ) stop () error {
96- p .done <- struct {}{}
96+ if ! p .active .Load () {
97+ return nil // already stopped
98+ }
9799
98100 errs := make ([]error , 0 )
99101
102+ select {
103+ case p .done <- struct {}{}:
104+ // no-op
105+ default :
106+ errs = append (errs , errors .New ("double-closing the pump" ))
107+ }
108+
100109 countdown := 60
101110 for p .active .Load () && countdown > 0 {
102111 time .Sleep (time .Second )
@@ -147,7 +156,14 @@ func (p *websocketPump) pumpMessages(
147156
148157 msgType , bytes , err := from .ReadMessage ()
149158 if err != nil {
150- failure <- err
159+ select {
160+ case failure <- err :
161+ // no-op
162+ default :
163+ l .Warn ("Dropping websocket pump failure b/c the channel is full" ,
164+ zap .Error (err ),
165+ )
166+ }
151167 continue
152168 }
153169
You can’t perform that action at this time.
0 commit comments