Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncatchable "This socket has been ended by the other party" when proxying websockets #1432

Open
flotwig opened this issue Apr 6, 2020 · 2 comments · May be fixed by #1433
Open

Uncatchable "This socket has been ended by the other party" when proxying websockets #1432

flotwig opened this issue Apr 6, 2020 · 2 comments · May be fixed by #1433

Comments

@flotwig
Copy link

flotwig commented Apr 6, 2020

Sometimes, errors are thrown from line 115 here:

proxyReq.on('response', function (res) {
// if upgrade event isn't going to happen, close the socket
if (!res.upgrade) {
socket.write(createHttpHeader('HTTP/' + res.httpVersion + ' ' + res.statusCode + ' ' + res.statusMessage, res.headers));
res.pipe(socket);
}
});

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.

@theomessin
Copy link

Bump

@FinnStutzenstein
Copy link

See #1552

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants