Skip to content

websocket: make the output dial honour its context - #484

Open
Leward wants to merge 1 commit into
VM-75-f-03-websocket-dial-contextfrom
VM-75-f-03-websocket-output-dial-context
Open

websocket: make the output dial honour its context#484
Leward wants to merge 1 commit into
VM-75-f-03-websocket-dial-contextfrom
VM-75-f-03-websocket-output-dial-context

Conversation

@Leward

@Leward Leward commented Aug 28, 2026

Copy link
Copy Markdown

The output dial takes a context and discards it. A peer that accepts TCP and then stays silent keeps Connect blocked until the dialer handshake timeout of 45s, which blocks a graceful shutdown for that whole time.

Replace the dial with dialContext, which the input already uses. The tls and non-tls paths now differ only by the dialer field they set, so the duplicated dial call goes away.

Connect and ConnectionTest both pass a real context, and the async writer gives Connect a soft stop context. A dial to a silent peer now ends with the context error instead of running to the handshake timeout.

Add a test mirroring the input test, using the shared listener helpers so it only adds the writer constructors.

Refs:

  • CON-545
  • VM-75

@claude

claude Bot commented Aug 28, 2026

Copy link
Copy Markdown

Commits

LGTM

Review

Small, well-scoped fix: websocketWriter.dial now routes through the shared dialContext helper instead of dialer.Dial, so the output honours its context during both the TCP/TLS handshake and the websocket upgrade exchange. The TLS and non-TLS branches collapse to a single dial call that differs only in which dialer field is set, matching the shape already used by websocketReader.getConn. Connect and ConnectionTest both forward a real context, and the added table-driven test mirrors the input test exactly (cancelled-before-dial, cancelled-mid-handshake, deadline-exceeded-mid-handshake), reusing the existing newHangingListener / newUnreachableAddr / awaitWithin / requireAccepted helpers rather than duplicating them. The CHANGELOG entry is correctly widened from Input to Input/Output.

Checked and found clean: the context-error path in dialContext closes any conn it produced before returning, so Connect cannot cache a live client after a context error; the deferred res.Body.Close() still runs on that path; ConnectionTest only touches conn when err is nil; and no goroutine or listener introduced by the test helpers outlives the subtest.

LGTM

The output dial takes a context and discards it. A peer that accepts TCP and
then stays silent keeps Connect blocked until the dialer handshake timeout of
45s, which blocks a graceful shutdown for that whole time.

Replace the dial with dialContext, which the input already uses. The tls and
non-tls paths now differ only by the dialer field they set, so the duplicated
dial call goes away.

Connect and ConnectionTest both pass a real context, and the async writer
gives Connect a soft stop context. A dial to a silent peer now ends with the
context error instead of running to the handshake timeout.

Add a test mirroring the input test, using the shared listener helpers so it
only adds the writer constructors.
@Leward
Leward force-pushed the VM-75-f-03-websocket-output-dial-context branch from 152df18 to eb9ed68 Compare September 1, 2026 18:01
@claude

claude Bot commented Sep 1, 2026

Copy link
Copy Markdown

Commits
LGTM

Review
Small, focused change: the output 'websocket' dial now routes through the shared dialContext helper instead of dialer.Dial, so a peer that accepts TCP and then goes silent no longer pins shutdown to the 45s handshake timeout. The dial body is now identical to the input reader's, and the new test mirrors TestWebsocketConnectContextDone while reusing the existing listener helpers. Connect still closes the upgrade response body via defer, and dialContext closes any connection it returns on the context-error path, so no new leaks. CHANGELOG entry correctly widened to cover both components.

LGTM

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.

1 participant