Skip to content

Conversation

@KhafraDev
Copy link
Member

fixes #4628
closes #4631

isConnecting = state is 0 (CONNECTING)
onSocketClose sets state to 2 (CLOSING)

this way onSocketClose can only be called once

from #4631:

The issue was caused by onSocketClose() being called multiple times:

First call: When ws.close() is called before connection, it triggers:
    closeWebSocketConnection → failWebsocketConnection → onSocketClose()
Second call: The aborted fetch controller returns an error response, which triggers:
    failWebsocketConnection again → onSocketClose() again

@codecov-commenter
Copy link

codecov-commenter commented Oct 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.92%. Comparing base (a3166d3) to head (f82e476).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4632      +/-   ##
==========================================
- Coverage   92.94%   92.92%   -0.02%     
==========================================
  Files         106      106              
  Lines       33092    33086       -6     
==========================================
- Hits        30756    30746      -10     
- Misses       2336     2340       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@Uzlopak Uzlopak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of awaiting t.completed, you should await some resonable time like 250 ms.

Also dont use tspl, but use directly t.plan. tspl passes even if you have some asynchronous Activity after the test ended.

t.plan in node 20 works but does not have the waitFor option like in node 22+.

@KhafraDev KhafraDev requested a review from Uzlopak October 19, 2025 04:52
Copy link
Contributor

@Uzlopak Uzlopak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit cb2b04e into nodejs:main Oct 19, 2025
100 of 114 checks passed
@KhafraDev KhafraDev deleted the issue-4628 branch October 19, 2025 13:54
@github-actions github-actions bot mentioned this pull request Jan 5, 2026
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 this pull request may close these issues.

WebSocket fires both close and error events twice if the socket is closed before being opened.

4 participants