Skip to content

rgw/beast: dispatch connection close on strand during pause - #68600

Closed
lumir-sliva wants to merge 1 commit into
ceph:mainfrom
lumir-sliva:rgw-realm-reload-race
Closed

lumir-sliva wants to merge 1 commit into
ceph:mainfrom
lumir-sliva:rgw-realm-reload-race

Conversation

@lumir-sliva

Copy link
Copy Markdown
Contributor

Summary

Fixes a race between AsioFrontend::pause() and active keep-alive connections that crashes radosgw with a SIGSEGV in an io_context_pool thread during multisite period updates.

Problem

When radosgw-admin period update --commit on one zone pushes a new period to a peer, the peer's realm reloader calls AsioFrontend::pause(), which invokes ConnectionList::close() to shut down live connections before rebuilding the driver. close() iterates the list and calls socket.close() on every connection from the reloader thread — not from the connection's asio strand.

Each close makes the reactor deregister the socket's descriptor_state. If a keep-alive connection is concurrently starting its next async_read_some() on its strand (which happens right after serving the inbound POST /admin/realm/period that triggered the reload), epoll_reactor::start_op() dereferences a descriptor_state that close has already freed — segfault inside the beast read_some_op dispatch chain.

The stack trace on the teuthology run in the tracker matches: top frames are epoll_reactor::start_op → reactive_socket_service_base::async_receive → beast::http::detail::read_some_op.

Fix

Same pattern as 86ad0b8 (which fixed the timeout_timer running off the strand): anything that touches socket state from outside the strand has to be serialized with the coroutine.

  • Store the coroutine's strand executor on Connection at construction time (via yield.get_executor() in on_accept's spawn).
  • ConnectionList::close() now asio::dispatch()es the socket.close() onto each connection's strand, so it runs in order with the coroutine's own socket ops.
  • The dispatched lambda captures an intrusive_ptr<Connection> so the object outlives connections.clear(), which unlinks the list entry immediately.

Testing

  • Built radosgw with the change on a vstart multisite (2 zones, 1 zonegroup) set up via src/test/rgw/test-rgw-multisite.sh.
  • Wrote a reproducer that alternates zonegroup modify endpoint lists on the master, issues period update --commit on the secondary, and floods the master's multisite gateway with concurrent keep-alive curls during each cycle.
  • Unpatched main: SIGSEGV in epoll_reactor::start_op within the first few iterations, with the same signature as the tracker stack.
  • With this fix: 30 iterations clean, 43 realm reload cycles ("Frontends paused" / "Resuming frontends") recorded, no crashes.

test_period_update_commit in src/test/rgw/rgw_multi/tests.py (added in 5e6a9c8) already exercises this exact path — concurrent S3 writes while running multiple period-update-commit cycles. That's the test that hit this crash on Casey's 2026-04-17 trial and will gate the fix in the rgw/multisite teuthology suite.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
    • Includes unit test(s)
    • Includes integration test(s)
    • Includes bug reproducer
    • No tests

Tracker: https://tracker.ceph.com/issues/76094

AsioFrontend::pause() (and stop()) call ConnectionList::close() from
the realm reloader thread. That invokes socket.close() on every live
connection from a thread that isn't the connection's asio strand, so
the reactor deregisters each socket's descriptor_state racing against
the coroutine that handles the connection. If a keep-alive connection
is starting its next async_read_some() on its strand at the same time,
epoll_reactor::start_op() dereferences the descriptor_state that close
has already freed and radosgw segfaults in an io_context_pool thread.

This matches the race pattern fixed for timeout_timer in 86ad0b8:
any caller that touches socket state from outside the strand needs to
be serialized with the coroutine.

Store the coroutine's strand executor on Connection and dispatch the
close onto that strand in ConnectionList::close(). The lambda captures
an intrusive_ptr to Connection so the object lives until the close
actually runs, since connections.clear() unlinks the list entry right
after dispatch.

Tracker: https://tracker.ceph.com/issues/76094
Signed-off-by: Lumir Sliva <[email protected]>
@lumir-sliva
lumir-sliva requested a review from a team as a code owner April 24, 2026 11:25
@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

13 similar comments
@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@github-actions github-actions Bot added the rgw label Apr 24, 2026
@adamemerson

Copy link
Copy Markdown
Contributor

Sorry, I didn't notice this PR until now. I'm going to pull this commit onto pile of fixes I have, if that's all right.

@adamemerson

Copy link
Copy Markdown
Contributor

Sorry, I didn't notice this PR until now. I'm going to pull this commit onto pile of fixes I have, if that's all right.

I guess I did see it, but I'd forgotten about it. Either way, I'd like to get all the fixes together so we can backport them together rather than having a bunch of different ones.

@lumir-sliva

Copy link
Copy Markdown
Contributor Author

Sorry, I didn't notice this PR until now. I'm going to pull this commit onto pile of fixes I have, if that's all right.

I guess I did see it, but I'd forgotten about it. Either way, I'd like to get all the fixes together so we can backport them together rather than having a bunch of different ones.

No worries, happy to keep it as one commit in your series. Go for it.

@cbodley cbodley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, looks correct to me but i'll defer to @adamemerson when/where this merges

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@lumir-sliva

Copy link
Copy Markdown
Contributor Author

Closing this. The fix landed on main as 1430b88, folded into Adam's #68920 "rgw: Fix crashes on realm reload" (merged 2026-07-09). Same change, so no need for this one. Thanks Adam and Casey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants