broker: honor self-imposed ServerKeepAlive in read timeout#81
Merged
Conversation
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.
Closes #80.
Summary
When the broker overrides the client's requested keep-alive via
BrokerConfig.server_keep_alive(writingServerKeepAliveinto CONNACK per[MQTT-3.2.2-22]), it was continuing to compute its own read-timeout from the client's original requested value rather than the value it just imposed. PR #78 fixed the client side; this is the symmetric broker-side fix.In
build_connack_properties, after writing theServerKeepAliveproperty the broker now also updatesself.keep_alive, so the downstreamread_timeout = self.keep_alive * 1.5reflects the negotiated value.A small
clamp_keep_alive_to_u16helper logs a warning if aserver_keep_alive > u16::MAXseconds is configured (previously it silently clamped).Test
broker_read_timeout_uses_negotiated_keep_alive_not_client_requestopens a raw TCP socket, sends a hand-crafted CONNECT withkeep_alive = 600sagainst a broker configured withserver_keep_alive = 1s, sends no PINGREQs, and asserts the broker drops the connection within ~1.5s (negotiated) rather than ~900s (client request). Verified that reverting just theself.keep_aliveupdate makes this test fail with the expectedbroker did not close connection within 4s — read_timeout still using client's 600s requestmessage.Test plan
cargo test -p mqtt5 --test keepalive_negotiation(all 7 tests pass)cargo make ci-verifyclean