Uncatchable "This socket has been ended by the other party" when proxying websockets
Created by: flotwig
Sometimes, errors are thrown from line 115 here:
Error: This socket has been ended by the other party
at TLSSocket.writeAfterFIN [as write] (net.js:441:14)
at ClientRequest.<anonymous> (/home/person/cypress/packages/server/node_modules/http-proxy/lib/http-proxy/passes/ws-incoming.js:115:16)
at ClientRequest.emit (events.js:210:5)
at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:583:27)
at HTTPParser.parserOnHeadersComplete (_http_common.js:115:17)
at TLSSocket.socketOnData (_http_client.js:456:22)
at TLSSocket.emit (events.js:210:5)
at addChunk (_stream_readable.js:308:12)
at readableAddChunk (_stream_readable.js:289:11)
at TLSSocket.Readable.push (_stream_readable.js:223:10)
at TLSWrap.onStreamRead (internal/stream_base_commons.js:182:23)
This error can't be caught by passing an error handler to http-proxy.
I think a fix would be to check if the socket is destroyed before attempting to write to it.
Users are able to reproduce this while proxying websockets in real-world apps, it seems to be the result of some race condition as it fails unpredictably: cypress-io/cypress#6458
I haven't been able to come up with a small reproducible example for this bug yet.