Skip to content

Commit

Permalink
librbd/migration/HttpClient: avoid hitting an assert in advance_state()
Browse files Browse the repository at this point in the history
If the shutdown gets delayed until the state transition from
STATE_RESET_CONNECTING completes and the reconnect is successful
(i.e. next_state is STATE_READY), we eventually hit "unexpected
state transition" assert in advance_state().  The reason is that
advance_state() would update m_state and call disconnect() under
STATE_READY instead of STATE_SHUTTING_DOWN.  After the disconnect
maybe_finalize_shutdown() would enter advance_state() again with
STATE_SHUTDOWN as next_state, but the transition to that from
STATE_READY is invalid.

Plug this by not transitioning to next_state if current_state is
STATE_SHUTTING_DOWN.

Signed-off-by: Ilya Dryomov <[email protected]>
  • Loading branch information
idryomov committed Dec 13, 2024
1 parent 9fa0bcc commit 1046d61
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/librbd/migration/HttpClient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,13 @@ class HttpClient<I>::HttpSession : public HttpSessionInterface {
m_on_shutdown = on_finish;

auto current_state = m_state;
m_state = STATE_SHUTTING_DOWN;

if (current_state == STATE_UNINITIALIZED) {
// never initialized or resolve/connect failed
on_finish->complete(0);
return;
}

m_state = STATE_SHUTTING_DOWN;
if (current_state != STATE_READY) {
} else if (current_state != STATE_READY) {
// delay shutdown until current state transition completes
return;
}
Expand Down Expand Up @@ -501,7 +500,10 @@ class HttpClient<I>::HttpSession : public HttpSessionInterface {
<< "next_state=" << next_state << ", "
<< "r=" << r << dendl;

m_state = next_state;
if (current_state != STATE_SHUTTING_DOWN) {
m_state = next_state;
}

if (current_state == STATE_CONNECTING) {
if (next_state == STATE_UNINITIALIZED) {
shutdown_socket();
Expand Down

0 comments on commit 1046d61

Please sign in to comment.