Skip to content

fix(ws): support graceful client shutdown - #216

Open
Zhang-986 wants to merge 1 commit into
larksuite:v3_mainfrom
Zhang-986:codex/ws-client-graceful-stop
Open

fix(ws): support graceful client shutdown#216
Zhang-986 wants to merge 1 commit into
larksuite:v3_mainfrom
Zhang-986:codex/ws-client-graceful-stop

Conversation

@Zhang-986

Copy link
Copy Markdown

Summary

  • make Start unblock when its context is canceled instead of waiting on select {} forever
  • let Close cancel the running client context so callers can stop a started WebSocket client without restarting the process
  • make ping and reconnect sleeps context-aware, and skip reconnect after an intentional shutdown
  • guard connection state snapshots used by background loops so shutdown is clean under the race detector

This keeps the existing blocking Start shape for compatibility, but it is no longer unbounded: callers can stop it with either context cancellation or Close.

Fixes #204
Refs #190

Tests

  • go test ./ws -run TestPingLoopStopsWhenContextCanceled -count=1 (red before fix)
  • go test ./ws -run TestStartReturnsWhenContextCanceled -count=1 (red before fix)
  • go test ./ws -run TestCloseStopsStartedClient -count=1 (red before fix)
  • go test -race ./ws -count=1
  • go test ./ws -count=1
  • go test ./... -count=1
  • git diff --check

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.

ws 没有优雅停止吗

1 participant