Skip to content

fix(connection): retry failed session establishment - #761

Merged
wboayue merged 3 commits into
wboayue:mainfrom
faysou:fix/reconnect-session-establishment
Aug 27, 2026
Merged

fix(connection): retry failed session establishment#761
wboayue merged 3 commits into
wboayue:mainfrom
faysou:fix/reconnect-session-establishment

Conversation

@faysou

@faysou faysou commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Keep the sync and async reconnect loops active when the socket reopens but session establishment fails. This covers the interval where TWS accepts TCP connections before its API handshake is ready, such as during an automated restart.

stateDiagram-v2
    [*] --> ReconnectSocket
    ReconnectSocket --> EstablishSession: socket connected
    ReconnectSocket --> Backoff: socket error
    EstablishSession --> Connected: session ready
    EstablishSession --> Backoff: handshake or startup error
    Backoff --> ReconnectSocket: attempts remain
    Backoff --> Failed: attempts exhausted
Loading

A reconnect succeeds only after the complete session is ready. Transient establishment failures consume an attempt and follow the existing backoff policy.

Testing

  • cargo test -p ibapi --features sync.
  • Sync and async tests with an incompatible handshake followed by a valid handshake.
  • Paper TWS restart smoke: reconnect survived the startup window and downstream subscriptions resumed.

faysou and others added 3 commits August 17, 2026 02:20
- Retry when TCP reconnects before the TWS session is ready
- Cover sync and async paths with transient handshake tests
Exhausted reconnect attempts now return the final attempt's error instead
of a bare Error::ConnectionFailed, so a permanent cause (e.g. incompatible
server version) is named. Dispatchers still map any reconnect failure to
the ConnectionFailed sentinel, so loop-exit behavior is unchanged.
@wboayue

wboayue commented Aug 27, 2026

Copy link
Copy Markdown
Owner

Thanks @faysou. Retrying through the TWS startup window where the socket accepts but the handshake isn't ready is right.

I pushed two small additions to your branch:

  • reconnect() now returns the last attempt's error on exhaustion instead of a bare Error::ConnectionFailed, so a permanent cause (e.g. incompatible server version) is named rather than hidden. The dispatchers still produce the ConnectionFailed sentinel, so loop-exit behavior is unchanged.
  • Merged main and added a CHANGELOG entry under [Unreleased].

Will merge once CI is green.

@wboayue
wboayue merged commit 0c7fd33 into wboayue:main Aug 27, 2026
4 checks passed
wboayue added a commit to tradatious/rust-ibapi that referenced this pull request Aug 28, 2026
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.

2 participants