Skip to content

fix(sdk): keep an explicit disconnect until the next connect - #4388

Merged
hubcio merged 3 commits into
apache:masterfrom
TomPlanche:fix/sdk-disconnect-holds
Oct 12, 2026
Merged

hubcio merged 3 commits into
apache:masterfrom
TomPlanche:fix/sdk-disconnect-holds

Conversation

@TomPlanche

@TomPlanche TomPlanche commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

edit: after @jiengup's review, connect_inner refuses a reconnect while the disconnect holds, so a request in flight during disconnect() cannot reconnect through the recovery path. A unit test per transport covers it. A connect already past that check when disconnect() runs is problem 6 of #4287.
edit2: addressed @numinnex's review: per-step checks in all sweeps, redirect keeps the disconnect, heartbeat awaited, ClientShutdown kept after shutdown.

Which issue does this PR address?

Relates to #4287 (problems 2 and 3, and part of problems 6 and 8)

Rationale

An explicit disconnect() must hold until the next connect(), as agreed on #4287: the test in disconnect_relogin.rs is the correct contract, not the IggyClient docs. Problems 2 and 3 of #4287 break this rule for a client with auto-login credentials. This PR fixes these two problems.

What changed?

After disconnect(), a client with auto-login credentials came back on its own. The heartbeat kept running and its ping reconnected the client and signed in again, and a direct ping() or get_stats() did the same. Only an authenticated request such as get_me() failed, because fail_if_not_authenticated rejects it before the transport.

Now the Client trait impl of disconnect() sets a caller-intent flag on TCP, QUIC and WebSocket, and the trait impl of connect() clears it. While the flag is set, send_raw_with_response fails with NotConnected at once: no packets on the wire, no wait, no reconnect. The flag lives only in the trait impl, because leader redirection and the reconnect path call the inherent disconnect(). A connection that drops without disconnect() leaves the flag clear, so that loss still heals. IggyClient::disconnect also stops the heartbeat, and connect starts it again. This removes the useless pings, and on QUIC it removes the redial that blocked disconnect() in endpoint.wait_idle().

The Client trait now documents the disconnect() contract. The IggyClient, Python and C++ docs no longer say that auto-login undoes a disconnect. The last two lifecycle tests from #4344 lose their #[ignore], so all 10 cases of client_lifecycle.rs now run.

Local Execution

I used Zed in devcontainer mode. The build and the tests ran in the devcontainer, and prek ran on macOS.

  • Passed: cargo fmt --all and cargo clippy -p iggy_common -p iggy -p integration --all-features --all-targets -- -D warnings.

  • Passed: cargo test -p iggy --lib, with 234 tests.

  • Passed: the lifecycle tests, with all 10 cases and none ignored, in 3 runs out of 3:

    $ cargo test -p integration -- sdk::client_lifecycle
    test result: ok. 10 passed; 0 failed; 0 ignored; 0 measured; 991 filtered out
    
  • Passed: the sdk:: integration suite (69 passed, 0 ignored), which includes disconnect_relogin.rs, and the cluster:: suite (80 passed), because the flag sits in the reconnect path that failovers use.

  • Passed: the Python lifecycle tests against a local server:

    $ uv run --no-sync pytest tests/test_connectivity.py -k Lifecycle
    16 passed, 35 deselected
    
  • Passed: cargo run --bin stub_gen. The stub diff contains only the disconnect() docstring.

  • Passed: pre-commit hooks with SKIP=web-lint prek run --all-files. I skipped web-lint because this PR does not change web/.

AI Usage

  1. None for the code, tried to write this PR body with Claude but finished with some 200+ lines slop.

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

Thanks for the PR. It is labeled S-waiting-on-review and queued for review.

Slash commands (own line, regular comment) move it around the queue:

  • /ready - back to S-waiting-on-review after addressing feedback
  • /author - flip to S-waiting-on-author while you finish changes
  • /request-review @user-or-team - request a reviewer
  • /pin - exempt the PR from the stale bot, /unpin to undo

See CONTRIBUTING.md for details.

@github-actions github-actions Bot added the S-waiting-on-review PR is waiting on a reviewer label Oct 2, 2026
@codecov

codecov Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.34483% with 34 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.12%. Comparing base (d3e95f5) to head (66a113a).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
core/sdk/src/quic/quic_client.rs 83.87% 9 Missing and 1 partial ⚠️
core/sdk/src/websocket/websocket_client.rs 72.97% 9 Missing and 1 partial ⚠️
core/sdk/src/tcp/tcp_client.rs 91.66% 4 Missing and 5 partials ⚠️
core/sdk/src/clients/client.rs 82.35% 1 Missing and 2 partials ⚠️
core/sdk/src/client_wrappers/binary_client.rs 75.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #4388      +/-   ##
============================================
- Coverage     88.17%   88.12%   -0.05%     
  Complexity     1726     1726              
============================================
  Files          1314     1314              
  Lines        264085   264306     +221     
  Branches     222739   222960     +221     
============================================
+ Hits         232859   232923      +64     
- Misses        25734    25840     +106     
- Partials       5492     5543      +51     
Components Coverage Δ
Rust Core 89.83% <85.34%> (-0.04%) ⬇️
Java SDK 70.18% <ø> (ø)
C# SDK 65.92% <ø> (-0.49%) ⬇️
Python SDK 90.38% <ø> (ø)
PHP SDK 85.84% <ø> (ø)
Node SDK 95.14% <ø> (ø)
Go SDK 70.37% <ø> (-0.03%) ⬇️
C++ SDK 84.43% <ø> (ø)
Files with missing lines Coverage Δ
...e/sdk/src/clients/binary_personal_access_tokens.rs 100.00% <ø> (ø)
core/sdk/src/clients/binary_users.rs 100.00% <ø> (ø)
foreign/cpp/include/iggy.hpp 86.59% <ø> (ø)
foreign/python/src/client.rs 99.76% <ø> (ø)
core/sdk/src/client_wrappers/binary_client.rs 87.50% <75.00%> (-12.50%) ⬇️
core/sdk/src/clients/client.rs 90.57% <82.35%> (-0.42%) ⬇️
core/sdk/src/tcp/tcp_client.rs 92.67% <91.66%> (-0.11%) ⬇️
core/sdk/src/quic/quic_client.rs 85.91% <83.87%> (+0.18%) ⬆️
core/sdk/src/websocket/websocket_client.rs 86.04% <72.97%> (-0.44%) ⬇️

... and 52 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread core/sdk/src/tcp/tcp_client.rs Resolved
@TomPlanche

Copy link
Copy Markdown
Contributor Author

/request-review @jiengup

@TomPlanche

Copy link
Copy Markdown
Contributor Author

/request-review @hubcio

@github-actions
github-actions Bot requested review from hubcio and jiengup October 5, 2026 12:36
Comment thread core/sdk/src/tcp/tcp_client.rs Resolved
Comment thread core/sdk/src/tcp/tcp_client.rs Resolved
Comment thread core/sdk/src/clients/client.rs Resolved
Comment thread core/sdk/src/tcp/tcp_client.rs Resolved
Comment thread core/common/src/traits/client.rs Resolved
Comment thread core/sdk/src/quic/quic_client.rs Resolved
Comment thread foreign/python/src/client.rs Resolved
@TomPlanche

Copy link
Copy Markdown
Contributor Author

Thanks @numinnex for the great review. I checked each point against the code, and these five hold:

  • tcp_client.rs:659: the send guard turns a disconnect during an auto-login sweep into an endless redial, because fail_sign_in reads NotConnected as a lost connection.
  • tcp_client.rs:176: the leader redirect in login_user goes through the trait connect(), so it clears the flag and undoes the disconnect.
  • client.rs:1006: the aborted heartbeat can leave the client in Connecting, and the TCP disconnect() then returns early with no teardown.
  • tcp_client.rs:235: the send guard has no unit test, and after shutdown() it hides ClientShutdown behind NotConnected.
  • quic_client.rs:707: the QUIC and WebSocket ladders can still install a connection after the disconnect.

The doc and test nits are valid too.

So a flag checked at the entry points is not enough: it must be checked at every step of the reconnect sweep, on all three transports. That is the same code #4345 changes, and close to problems 5 to 8 of #4287 and to #3651. I asked on #4287 how you want it scoped before I change more of the state machine.

@TomPlanche

Copy link
Copy Markdown
Contributor Author

/ready

@TomPlanche

Copy link
Copy Markdown
Contributor Author

/request-review @numinnex

@github-actions
github-actions Bot requested a review from numinnex October 5, 2026 20:50
@hubcio

hubcio commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

@TomPlanche could you please rebase this?

@TomPlanche
TomPlanche force-pushed the fix/sdk-disconnect-holds branch from 78939bf to 9d1521a Compare October 10, 2026 23:39
@TomPlanche

Copy link
Copy Markdown
Contributor Author

@hubcio Rebased onto master. The conflicts were with #4387 the sign-in guard now sits on top of its new error handling.

@TomPlanche
TomPlanche force-pushed the fix/sdk-disconnect-holds branch from 9d1521a to 061ef48 Compare October 12, 2026 11:44
Comment thread core/sdk/src/clients/client.rs Resolved
Comment thread core/sdk/src/tcp/tcp_client.rs Resolved
@github-actions github-actions Bot added S-waiting-on-author PR is waiting on author response and removed S-waiting-on-review PR is waiting on a reviewer labels Oct 12, 2026
@TomPlanche

Copy link
Copy Markdown
Contributor Author

/ready

@github-actions github-actions Bot added S-waiting-on-review PR is waiting on a reviewer and removed S-waiting-on-author PR is waiting on author response labels Oct 12, 2026
@hubcio
hubcio merged commit 8ded547 into apache:master Oct 12, 2026
82 checks passed
@github-actions github-actions Bot removed the S-waiting-on-review PR is waiting on a reviewer label Oct 12, 2026
hubcio added a commit that referenced this pull request Oct 13, 2026
Backups refused requests without directing clients to a partition's
primary. HTTP tried writes on every node, and partition lookup
required send permission.

Add command 105 for partition routes with send or poll permission,
NotPrimary (89), and replica IDs in cluster metadata. Routes carry
incarnation, frontier and view. HTTP forwards to the partition primary
in one hop; stale routes cannot chain relays.

Run reads, polls and metadata commit waits outside the connection
drain. Serialize metadata writes per connection and serve QUIC streams
concurrently to prevent stalls.

The Rust SDK shares session state, correlates TCP/WebSocket replies by
request ID and bounds QUIC requests by deadlines. Add a driver with
cached routes, one link per replica and one mutation at a time per
partition history and for metadata. Clients do not use the driver yet.

Derive owner generations from metadata ops to fence recreated groups.
IGGY-OWNERSHIP-HISTORY-5 rejects older data before modifying it. Fence
old partition control frames with incarnation in reserved bytes,
preserving header sizes and field offsets.

Close the owner handoff, retirement and offset-transfer gaps found in
transfer emptied-table markers with offsets artifact v8. Exhausted
partition repair windows escalate to state transfer. Rotations
preserve the session ceiling and yield capacity; transfers reset
repair budgets.

Prove retained StartView history before committing or serving repair.
Preserve unresolved proof across failed truncation and view changes,
and retain acknowledged tails on commit-only updates. Metadata
recovery protects pipeline-owned prepares; internal completions no
longer become external reply attempts.

Carry the transport disconnect fix from #4388 and retry relayed reads
after primary failure. Simulator checks cover replacement histories
and restarts. Keep unresolved requests through same-session re-login
and transient refusals, bind the refusing endpoint and preserve
committed-offset flags across restart.

After offset file loss at boot, including all files or a whole kind
directory, deleting the donor's last key can emit an emptied-table
marker that drops those offsets on lagging receivers. That key may
have been written after boot. Deleted groups remain only while
stranded offsets are durable, avoiding permanent catalog retention for
unreadable or unremovable files.
hubcio added a commit that referenced this pull request Oct 14, 2026
Backups refused requests without directing clients to a partition's
primary. HTTP tried writes on every node, and partition lookup
required send permission.

Add command 105 for partition routes with send or poll permission,
NotPrimary (89), and replica IDs in cluster metadata. Routes carry
incarnation, frontier and view. HTTP forwards to the partition primary
in one hop; stale routes cannot chain relays.

Run reads, polls and metadata commit waits outside the connection
drain. Serialize metadata writes per connection and serve QUIC streams
concurrently to prevent stalls.

The Rust SDK shares session state, correlates TCP/WebSocket replies by
request ID and bounds QUIC requests by deadlines. Add a driver with
cached routes, one link per replica and one mutation at a time per
partition history and for metadata. Clients do not use the driver yet.

Derive owner generations from metadata ops to fence recreated groups.
IGGY-OWNERSHIP-HISTORY-5 rejects older data before modifying it. Fence
old partition control frames with incarnation in reserved bytes,
preserving header sizes and field offsets.

Close the owner handoff, retirement and offset-transfer gaps found in
transfer emptied-table markers with offsets artifact v8. Exhausted
partition repair windows escalate to state transfer. Rotations
preserve the session ceiling and yield capacity; transfers reset
repair budgets.

Prove retained StartView history before committing or serving repair.
Preserve unresolved proof across failed truncation and view changes,
and retain acknowledged tails on commit-only updates. Metadata
recovery protects pipeline-owned prepares; internal completions no
longer become external reply attempts.

Carry the transport disconnect fix from #4388 and retry relayed reads
after primary failure. Simulator checks cover replacement histories
and restarts. Keep unresolved requests through same-session re-login
and transient refusals, bind the refusing endpoint and preserve
committed-offset flags across restart.

After offset file loss at boot, including all files or a whole kind
directory, deleting the donor's last key can emit an emptied-table
marker that drops those offsets on lagging receivers. That key may
have been written after boot. Deleted groups remain only while
stranded offsets are durable, avoiding permanent catalog retention for
unreadable or unremovable files.
hubcio added a commit that referenced this pull request Oct 14, 2026
Backups refused requests without directing clients to a partition's
primary. HTTP tried writes on every node, and partition lookup
required send permission.

Add command 105 for partition routes with send or poll permission,
NotPrimary (89), and replica IDs in cluster metadata. Routes carry
incarnation, frontier and view. HTTP forwards to the partition primary
in one hop; stale routes cannot chain relays.

Run reads, polls and metadata commit waits outside the connection
drain. Serialize metadata writes per connection and serve QUIC streams
concurrently to prevent stalls.

The Rust SDK shares session state, correlates TCP/WebSocket replies by
request ID and bounds QUIC requests by deadlines. Add a driver with
cached routes, one link per replica and one mutation at a time per
partition history and for metadata. Clients do not use the driver yet.

Derive owner generations from metadata ops to fence recreated groups.
IGGY-OWNERSHIP-HISTORY-5 rejects older data before modifying it. Fence
old partition control frames with incarnation in reserved bytes,
preserving header sizes and field offsets.

Close the owner handoff, retirement and offset-transfer gaps found in
transfer emptied-table markers with offsets artifact v8. Exhausted
partition repair windows escalate to state transfer. Rotations
preserve the session ceiling and yield capacity; transfers reset
repair budgets.

Prove retained StartView history before committing or serving repair.
Preserve unresolved proof across failed truncation and view changes,
and retain acknowledged tails on commit-only updates. Metadata
recovery protects pipeline-owned prepares; internal completions no
longer become external reply attempts.

Carry the transport disconnect fix from #4388 and retry relayed reads
after primary failure. Simulator checks cover replacement histories
and restarts. Keep unresolved requests through same-session re-login
and transient refusals, bind the refusing endpoint and preserve
committed-offset flags across restart.

After offset file loss at boot, including all files or a whole kind
directory, deleting the donor's last key can emit an emptied-table
marker that drops those offsets on lagging receivers. That key may
have been written after boot. Deleted groups remain only while
stranded offsets are durable, avoiding permanent catalog retention for
unreadable or unremovable files.
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.

4 participants