Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #140 +/- ##
=======================================
Coverage ? 76.59%
=======================================
Files ? 9
Lines ? 735
Branches ? 147
=======================================
Hits ? 563
Misses ? 170
Partials ? 2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@pi0 Can you review this when you get a chance please good Sir? |
|
Sure :) I have to double check |
Error: read ECONNRESET on Windows when sending response| } | ||
| } | ||
| if (socket.writable) { | ||
| socket.end(); |
There was a problem hiding this comment.
I'm still little worried that we are not using end callback on socket.
This way, handleUpgrade promise is resolved even before socket closes.
Do you have a stable reproduction that all this changes fixes it? (asking cause I tried closing socket on windows by enabling this condition => pnpm play:node. i can't see errors on windows.
There was a problem hiding this comment.
I'll update the code so that we destroy the socket in the socket.end() callback.
I've also updated the reproduction from the issue with the solution that fixes the issue https://github.com/eltigerchino/crossws-windows-socket-error-repro . There's a line you can uncomment to destroy the socket to fix it.
Strangely, I can reproduce this error on Windows by running pnpm play:node then sending a WebSocket request through Hoppscotch at the URL http://localhost:3001/?unauthorized.
PS C:\git-windows\crossws> pnpm play:node
> crossws@0.3.4 play:node C:\git-windows\crossws
> jiti test/fixture/node.ts
Server running at http://localhost:3001/
node:events:495
throw er; // Unhandled 'error' event
^
Error: read ECONNRESET
at TCP.onStreamRead (node:internal/stream_base_commons:217:20)
Emitted 'error' event on Socket instance at:
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
errno: -4077,
code: 'ECONNRESET',
syscall: 'read'
}
Node.js v18.20.5
ELIFECYCLE Command failed with exit code 1.
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment Thanks for integrating Codecov - We've got you covered ☂️ |
|
thanks for update and sorry for delay! |
fixes #139
This PR is an attempt to to avoid the error that's occurring on Windows from calling
socket.write(chunk)by destroying the socket stream after all data has been written. It copies theSocket.destroySoon()implementation from Node.js.Also worth noting that the
wsexamples usesocket.destroy()to end their upgrade requests:And the duplex stream/socket class uses the
Writable.destroy()implementation:https://nodejs.org/api/stream.html#writabledestroyerror
EDIT: seems like
wsalso callssocket.destroy()when sending their responses too, according to their implementation