Skip to content

flake: TestOneWayWebSocketEventSender/Renders_the_socket_inert_if_the_request_context_cancels #1429

@flake-investigator

Description

@flake-investigator

CI Run: https://github.com/coder/coder/actions/runs/23694806573
Job: test-go-pg-17 (failed at 2026-03-28T21:40:35Z)
Commit: a399aa8c0cc50e0023c15893aaaa9eb64328bd88 (Danielle Maywood) coder/coder@a399aa8

Failure:

=== FAIL: coderd/httpapi TestOneWayWebSocketEventSender/Renders_the_socket_inert_if_the_request_context_cancels (5.02s)
    httpapi_test.go:377:
        Error Trace: /home/runner/work/coder/coder/coderd/httpapi/httpapi_test.go:377
        Error:       Not equal:
                     expected: <nil>(<nil>)
                     actual  : *errors.errorString(&errors.errorString{s:"context canceled"})

Notes / error analysis:

  • The test cancels the request context, waits for the done channel, and expects send(...) to return ctx.Err().
  • Observed behavior: send(...) returned nil, so require.Equal(t, err, ctx.Err()) failed with expected nil vs actual context canceled.

Likely root cause:

  • OneWayWebSocketEventSender uses a select with case eventC <- event: and case <-ctx.Done(): return ctx.Err(). After context cancellation, both cases can be ready (buffered channel send is immediately available), which makes the result nondeterministic. This leads to occasional nil from send(...) even though the context is canceled.
  • The event channel was recently changed to buffered (64) in coder/coder@386b449, increasing the chance of the send case winning after cancellation.

Assignment analysis:

  • Recent commits touching the failing test file /coderd/httpapi/httpapi_test.go: coder/coder@612aae2, coder/coder@9bc727e
  • Recent commits touching /coderd/httpapi/httpapi.go (contains OneWayWebSocketEventSender): coder/coder@386b449, coder/coder@612aae2
  • The most recent substantive change to the sender behavior is 386b449 (Kyle Carberry), which introduced buffering and likely created this nondeterministic outcome.

Suggested fix direction:

  • Make sendEvent deterministic on cancellation (e.g., check ctx.Err() before attempting the send, or prioritize ctx.Done() when it is closed).

No data race/panic/OOM indicators found in logs.
Related issues: none found (searches: TestOneWayWebSocketEventSender, OneWayWebSocketEventSender, httpapi_test.go, context canceled).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions