Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pubsub): Implement Ping/Pong Mechanism to Improve Connection Reliability #3845

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

0xIchigo
Copy link

Problem

Both the blocking and nonblocking PubsubClient clients currently lack a mechanism to detect when the WebSocket connection becomes unresponsive or stale. Without periodic health checks, the clients may not realize that the server is no longer responding. This can lead to missed messages and unreliable subscriptions. This can affect applications relying on WebSockets to provide real-time data streams

Summary of Changes

This PR aims to implement a ping/pong mechanism in both the blocking and nonblocking PubsubClient clients to improve connection reliability

Changes

  • Introduced a periodic Ping message sent to the server using tokio::time::interval
  • Added handling for incoming Pong messages and reset the unmatched_pings counter upon receiving any message
  • Configured the client to close the connection gracefully if the unmatched_pings counter exceeds DEFAULT_MAX_FAILED_PINGS
  • Ensured the changes did not significantly alter the existing code structure. This meant hardcoding DEFAULT_PING_DURATION_SECONDS and DEFAULT_MAX_FAILED_PINGS, as making them configurable would've meant changing the existing subscription parameters resulting in a breaking change. However, these params could easily be changed in the future to become configurable—the importance here is introducing reliable health checks to WebSocket connections

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant