Skip to content

fix(ws): make WebSocket client lifecycle cancellable - #244

Merged
SadMemories merged 7 commits into
v3_mainfrom
fix/make-websocket-client-lifecycle-cancellable-2
Aug 28, 2026
Merged

SadMemories merged 7 commits into
v3_mainfrom
fix/make-websocket-client-lifecycle-cancellable-2

Conversation

@SadMemories

@SadMemories SadMemories commented Aug 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • make Client.Start stop deterministically for caller cancellation, explicit Close, and terminal connection errors
  • preserve public bootstrap error types and synchronous lifecycle callback delivery
  • detect half-open connections with read deadlines, and bound WebSocket writes so read or write failures enter the reconnect flow
  • remove the bootstrap dependency on the global HTTP client: add WithHttpClient and WithWebSocketDialer, with a bounded default bootstrap HTTP client
  • keep Close callback-safe and non-blocking; add CloseAndWait(ctx) for callers that must wait for connection teardown, OnDisconnected, and SDK workers
  • restore legacy lifecycle log wording and per-connection conn_id output

Fixed issues

Fixes #189
Fixes #201
Fixes #204
Fixes #224

Notes

  • CloseAndWait(ctx) must be called outside lifecycle callbacks; callbacks should call Close() to avoid waiting for the coordinator that is currently executing them.
  • Ping may start before OnReady / OnReconnected returns, consistent with the accepted behavior for this PR.

Validation

  • go test -count=1 -race ./ws
  • go test ./...
  • IM sample: Code 0
  • event and card mocks: HTTP 200
  • WebSocket sample: connected, ping success, receive pong

@SadMemories
SadMemories force-pushed the fix/make-websocket-client-lifecycle-cancellable-2 branch from 32e0bbb to 22e52b4 Compare August 28, 2026 02:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment