Repository navigation
fix: handle websocket closed correctly - #3565
Merged
Merged
Conversation
Co-authored-by: eXhumer <exhumer@exhumer.cc>
KhafraDev
marked this pull request as ready for review
September 7, 2024 21:15
Contributor
|
Related issue needs to be re-opened as I don't think issue is fixed. Infact, the test was modified which doesn't check the close event firing. Issue re-producible with the following code import { WebSocket } from 'undici';
const ws = new WebSocket('ws://localhost:8080');
ws.onclose = e => {
console.log('close', e);
};
ws.onerror = e => {
console.log('error', e);
};Console output |
eXhumer
reviewed
Sep 8, 2024
| const { tspl } = require('@matteo.collina/tspl') | ||
|
|
||
| test('first error than close event is fired on failed connection', async (t) => { | ||
| const { completed, strictEqual } = tspl(t, { plan: 2 }) |
Contributor
There was a problem hiding this comment.
{ plan: 2 } skips close event check
Contributor
|
Test output with fixed websocket test. |
3 of 5 tasks
Uzlopak
pushed a commit
that referenced
this pull request
Sep 20, 2024
Merged
Closed
This was referenced May 11, 2025
Closed
This was referenced May 15, 2025
3 of 7 tasks
christianaurichzm
added a commit
to christianaurichzm/undici
that referenced
this pull request
Nov 19, 2026
A WebSocket whose connection fails before it is established (a refused TCP connection, a non-101 response or an invalid opening handshake) fires `error` and never `close`, and its readyState stays CONNECTING. The spec closes the connection after failing it, so `close` has to follow `error`, with code 1006 and readyState CLOSED. onSocketClose is only attached once the handshake succeeds, so failWebsocketConnection now closes a connection that is still CONNECTING itself. The fetch that close() aborts no longer fails the connection a second time, which used to fire a second `error`. This matches main, where it was fixed by nodejs#3565 and nodejs#3566 after v6.x branched. Refs: nodejs#3546 Signed-off-by: Christian Aurich Zanettini Martins <christian.aurichzm@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3546
Closes #3548