Skip to content

Ensure only one active ping worker per connection#50

Open
centurysys wants to merge 1 commit intopython36:masterfrom
centurysys:fix/ping-worker-lifecycle
Open

Ensure only one active ping worker per connection#50
centurysys wants to merge 1 commit intopython36:masterfrom
centurysys:fix/ping-worker-lifecycle

Conversation

@centurysys
Copy link
Copy Markdown
Contributor

When reconnecting, runPing() is started again while previous ping workers may still be running. Since the worker references ctx (and not a specific socket instance), it can continue operating after a reconnect and use the updated socket.

This can result in multiple concurrent ping workers sending PINGREQ frames at the keepAlive interval.

Introduce a simple generation guard (pingWorkerId) that is incremented on each successful connection. Each ping worker stores the generation it was started with and exits if it detects a newer generation.

This guarantees that only one active ping worker exists per connection without introducing additional synchronization primitives or changing public APIs.

When reconnecting, runPing() is started again while previous ping
workers may still be running. Since the worker references `ctx`
(and not a specific socket instance), it can continue operating
after a reconnect and use the updated socket.

This can result in multiple concurrent ping workers sending
PINGREQ frames at the keepAlive interval.

Introduce a simple generation guard (pingWorkerId) that is
incremented on each successful connection. Each ping worker
stores the generation it was started with and exits if it
detects a newer generation.

This guarantees that only one active ping worker exists per
connection without introducing additional synchronization
primitives or changing public APIs.

Signed-off-by: Takeyoshi Kikuchi <kikuchi@centurysys.co.jp>
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