Skip to content

fix: prevent worker crashes after WebSocket connection timeouts - #1346

Merged
DudaGod merged 1 commit into
masterfrom
INFRADUTY-30708.fix_ws_connection_timeout
Oct 20, 2026
Merged

DudaGod merged 1 commit into
masterfrom
INFRADUTY-30708.fix_ws_connection_timeout

Conversation

@DudaGod

@DudaGod DudaGod commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

What is done

Fixed a worker crash caused by late WebSocket errors after a connection timeout. Previously, the old connection could remain active without an error handler and crash the worker even after a retry succeeded.

Now cancel timed-out connections and handle errors until the socket closes. Also fixed close() so it cancels an ongoing connection attempt and prevents new attempts afterward.

More info in ticket

@pkg-pr-new

pkg-pr-new Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/gemini-testing/testplane@1346

commit: 41bc36c

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

✅ Testplane E2E run succeed

Report

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

✅ Testplane browser-env run succeed

Report

@DudaGod
DudaGod force-pushed the INFRADUTY-30708.fix_ws_connection_timeout branch from 1d9693e to f5b521c Compare October 15, 2026 11:28
@DudaGod
DudaGod marked this pull request as ready for review October 15, 2026 12:02

@shadowusr shadowusr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me! 🔥


const isClosing = status === WsConnectionStatus.CLOSED;

this._wsConnectionStatus = status;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

codex rightfully complains that when forceReconnect is called multiple times while a connection is still opening, previous connections aren't cancelled and only newest attempt will be tracked. Previous ones will be left hanging.

Before, we had a guard if !ws, but now we don't have it

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes, you're right. Thanks

@DudaGod DudaGod changed the title fix: I prevent worker crashes after WebSocket connection timeouts fix: prevent worker crashes after WebSocket connection timeouts Oct 20, 2026
@DudaGod
DudaGod force-pushed the INFRADUTY-30708.fix_ws_connection_timeout branch from f5b521c to 41bc36c Compare October 20, 2026 10:24
// Keep a handler until close because the attempt has already removed its listeners.
const onError = (): void => {};

ws.on("error", onError);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

the main fix for the problem

} else {
ws.once("open", () => {
ws.close();
if (ws.readyState === ws.CONNECTING) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Method close() aborts a CONNECTING handshake and emits an error on the next tick.
Keep a handler until close because the attempt has already removed its listeners.

closeWsConnection(ws);

const onUnexpectedResponse = async (_ws: WebSocket, res: IncomingMessage): Promise<void> => {
const reason = await consumeText(res).catch(() => "Unknown reason");

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Read the HTTP error before aborting, otherwise cancellation can replace its status and body.


const isClosing = status === WsConnectionStatus.CLOSED;

this._wsConnectionStatus = status;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes, you're right. Thanks

@DudaGod
DudaGod merged commit 241ecd3 into master Oct 20, 2026
7 of 9 checks passed
@DudaGod
DudaGod deleted the INFRADUTY-30708.fix_ws_connection_timeout branch October 20, 2026 10:37
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.

2 participants