Skip to content

fix: end a shutdown even when the store refuses the Logout - #356

Open
fraVlaca wants to merge 1 commit into
Validus-Risk-Management:mainfrom
fraVlaca:fix/shutdown-when-store-refuses-logout
Open

fraVlaca wants to merge 1 commit into
Validus-Risk-Management:mainfrom
fraVlaca:fix/shutdown-when-store-refuses-logout

Conversation

@fraVlaca

Copy link
Copy Markdown

Problem

A graceful shutdown sends a Logout, and the Logout is persisted like every outbound message. If the store refuses the write, initiate_graceful_logout returns the error before the state changes. The session stays connected, Initiator::shutdown does not complete, and the connection loop keeps going.

This matters for stores that deliberately refuse writes. One example is a store fenced to a single writer, so that when another process takes over a session, the old process can no longer write to it. Shutting the old process down is exactly when its writes are refused.

Separately, shutdown(false) while the session is disconnected between reconnect attempts was ignored: there is no connection to log out of, so the request did nothing and the connection loop dialled again.

Change

In SessionState::initiate_graceful_logout:

  • If the Logout cannot be sent (its persist or sequence-number update fails), it is not sent; the writer is disconnected and the session moves to Disconnected with the requested reconnect flag. The error is logged as a warning.
  • When the session has no connection and is set to reconnect, a request without reconnect moves it to Disconnected { reconnect: false }, so the connection loop ends. A request with reconnect while disconnected is unchanged.

The normal path (Logout persisted and sent, then AwaitingLogout) is unchanged.

Tests

Unit tests in session.rs, using the existing TestStore with a new fail_add switch:

  • test_shutdown_disconnects_when_logout_cannot_be_persisted: nothing is written except a disconnect, and the session ends disconnected without reconnect.
  • test_end_of_session_logout_failure_keeps_reconnect: the same failure with reconnect: true disconnects but keeps reconnecting.
  • test_shutdown_while_disconnected_stops_reconnecting and test_shutdown_with_reconnect_while_disconnected_keeps_reconnecting.

I could not build this workspace locally, so I am relying on CI for the compile, clippy and test run.

This contribution is offered under the project's MIT licence.

A graceful shutdown sends a Logout, which is persisted like every outbound
message. When the store refuses it (for example a store that has been fenced
because another process took the session over), the error was returned
before the state changed: the session stayed connected and the connection
loop kept dialling and failing to log on.

Now a Logout that cannot be persisted is not sent; the connection is closed
and the session moves to Disconnected with the requested reconnect flag.
A shutdown without reconnect requested while the session is between
reconnect attempts also moves it to Disconnected { reconnect: false },
instead of being ignored, so the connection loop ends.
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