feat: add WebSocket heartbeat ping/pong with configurable interval and max-missed - #7
Merged
Merged
Conversation
…d max-missed Agent-Logs-Url: https://github.com/winguse/expose-rs/sessions/fa8f3bbd-9f7c-416a-bf06-a79910234c1a Co-authored-by: winguse <1443504+winguse@users.noreply.github.com>
Agent-Logs-Url: https://github.com/winguse/expose-rs/sessions/fa8f3bbd-9f7c-416a-bf06-a79910234c1a Co-authored-by: winguse <1443504+winguse@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
winguse
May 17, 2026 21:02
View session
winguse
marked this pull request as ready for review
May 17, 2026 22:32
Agent-Logs-Url: https://github.com/winguse/expose-rs/sessions/e326adf9-d49e-4739-88de-aee38e35c689 Co-authored-by: winguse <1443504+winguse@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the heartbeat (ping/pong) feature for the WebSocket tunnel between the expose-rs client and server.
Both sides send a WebSocket
Pingframe periodically. If noPongis received for too many consecutive pings, the connection is closed. The client retries after closure; the server only cleans up resources.Changes
expose-commonHeartbeatConfigstruct with:interval: Duration— how often to send a ping (default: 15 s, configurable via CLI)max_missed: u32— how many consecutive missed pongs before closing (default: 2, configurable via CLI)DEFAULT_HEARTBEAT_INTERVAL_SECSandDEFAULT_HEARTBEAT_MAX_MISSEDexpose_clientandexpose_serverexpose-clientmpsc::UnboundedSender<Vec<u8>>tompsc::UnboundedSender<Message>so that both binary frames andPingcontrol frames flow through the same writer taskrun_clientthat sends pings everyintervaland closes the connection aftermax_missedconsecutive missed pongsMessage::Pongin the receive loop to reset the missed-pong counterrun_client_once_with_channel_configto acceptHeartbeatConfig;run_client_onceuses defaults--heartbeat-intervaland--heartbeat-max-missedCLI arguments (with defaults 15 / 2)expose-serverrun_server_with_channel_confignow acceptsHeartbeatConfig;run_serveruses defaults--heartbeat-intervaland--heartbeat-max-missedCLI argumentsIntegration tests
HeartbeatConfig::default()(no behaviour change for existing tests)test_heartbeat_closes_dead_tunnel: verifies that when the client stops sending pongs, the server detects the timeout and closes the tunnel, and that a new client can reconnect cleanly afterwardsTesting
All 15 integration tests and 20 unit tests pass, including the new heartbeat test.