File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -217,9 +217,16 @@ func (r *remoteProcess) listen(ctx context.Context) {
217
217
218
218
r .closeErr = r .conn .Close (websocket .StatusNormalClosure , "normal closure" )
219
219
// If we were in r.conn.Read() we cancel the ctx, the websocket library closes
220
- // the websocket before we have a chance to. This is a normal closure.
221
- if r .closeErr != nil && strings .Contains (r .closeErr .Error (), "already wrote close" ) &&
222
- r .readErr != nil && strings .Contains (r .readErr .Error (), "context canceled" ) {
220
+ // the websocket before we have a chance to. Unfortunately there is a race in the
221
+ // the websocket library, where sometimes close frame has already been written before
222
+ // we even call r.conn.Close(), and sometimes it gets written during our call to
223
+ // r.conn.Close(), so we need to handle both those cases in examining the error that comes
224
+ // back. This is a normal closure, so report nil for the error.
225
+ readCtxCanceled := r .readErr != nil && strings .Contains (r .readErr .Error (), "context canceled" )
226
+ alreadyClosed := r .closeErr != nil &&
227
+ (strings .Contains (r .closeErr .Error (), "already wrote close" ) ||
228
+ strings .Contains (r .closeErr .Error (), "WebSocket closed" ))
229
+ if alreadyClosed && readCtxCanceled {
223
230
r .closeErr = nil
224
231
}
225
232
close (r .done )
You can’t perform that action at this time.
0 commit comments