Skip to content

honor --timeout during mqtt connect handshake#59

Merged
fabracht merged 3 commits intomainfrom
cli-connect-timeout
May 6, 2026
Merged

honor --timeout during mqtt connect handshake#59
fabracht merged 3 commits intomainfrom
cli-connect-timeout

Conversation

@fabracht
Copy link
Copy Markdown
Contributor

@fabracht fabracht commented May 5, 2026

Summary

mqdb list --timeout 2 (and every other CLI command) didn't honor --timeout during the MQTT CONNECT handshake. connect_client in crates/mqdb-cli/src/common.rs only wrapped the request/response wait in tokio::time::timeout; the underlying MqttClient::connect[_with_options] calls had no timeout. Against a TCP listener that accepts the connection but never sends CONNACK (silent broker, half-open NAT, firewall drop after SYN-ACK), every command would hang indefinitely.

Reported repro: timeout 8 mqdb list ... --timeout 2 exits 124 against a silent listener but ~2.0s against a healthy broker.

The fix wraps the connect future in tokio::time::timeout(Duration::from_secs(conn.timeout), ...) and surfaces connect to {broker} timed out after {N}s on expiry. Affects every command that goes through connect_client (list, read, create, update, delete, schema, constraint, watch, etc.).

mqdb-cli 0.7.5 → 0.7.6.

Test plan

  • cargo test -p mqdb-cli --test cli_test — 4 → 5 tests (one regression test added).
    • test_cli_connect_timeout_against_silent_listener spawns a std::net::TcpListener that accepts the connection without speaking MQTT, then asserts mqdb list ... --timeout 2 exits within 5s with a "timed out" error.
    • Verified to fail on main (pre-fix, exits at ~6s with "Connection reset by peer", missing "timed out") and pass with the fix (~2s).
  • cargo make clippy — clean (pedantic, all targets + wasm).
  • cargo make format-check — clean.
  • Pre-commit hook (format-check + clippy) ran on the commit and passed.
  • Manual repro against a Python silent listener: pre-fix, command hung past 8s (killed by timeout 8); post-fix, command exits in 2.018s with Error: "connect to 127.0.0.1:19999 timed out after 2s".
  • cargo test (default features) — full workspace clean (no regressions). The mqtt-bridge-gated mqtt_transport_heartbeat_roundtrip integration test (deprecated transport per CLAUDE.md) is environmentally flaky on a hardcoded port 11883; not a regression from this PR.

@fabracht fabracht merged commit 81fa829 into main May 6, 2026
5 checks passed
@fabracht fabracht deleted the cli-connect-timeout branch May 6, 2026 21:31
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