Skip to content

nvmeofgw: do not erase the current element inside a range-for - #73738

Open
evkuzin wants to merge 1 commit into
ceph:mainfrom
evkuzin:wip-nvmeofgw-beacon-timeout-erase
Open

evkuzin wants to merge 1 commit into
ceph:mainfrom
evkuzin:wip-nvmeofgw-beacon-timeout-erase

Conversation

@evkuzin

@evkuzin evkuzin commented Nov 10, 2026

Copy link
Copy Markdown

NVMeofGwMon::check_beacon_timeout() erases the timed-out gateway's entry from last_beacon (a std::map) while iterating it with a range-based for. Erasing the element the loop is positioned at and then letting the loop increment is undefined behaviour. It runs on every beacon timeout, so on every NVMe-oF gateway failover. libstdc++ with -D_GLIBCXX_DEBUG aborts on this shape with "attempt to increment a singular iterator"; release builds survive by luck because the freed node's links are usually still readable.

The fix iterates with an explicit iterator and advances with it = last_beacon.erase(it) on the timeout branch, the same idiom used elsewhere in src/mon (for example MDSMonitor.cc). Behaviour is otherwise unchanged. process_gw_map_gw_down() has no access to last_beacon, so the single pass remains valid.

Introduced by b49ac69 ("nvmeofgw: fast-failover changes"), shipped in v21.0.0 and backported to tentacle 20.2.1, so this needs backports to tentacle and umbrella.

Verification: no unit harness can construct NVMeofGwMon without a live monitor, so there is no new test. A standalone reproduction of both loop shapes over a std::map built with -D_GLIBCXX_DEBUG aborts on the old shape and completes on the new one.

A second instance of the same pattern exists in NVMeofGwMap::check_all_gws_in_deleting_state() (src/mon/NVMeofGwMap.cc:209), reached through nvme-gw delete; it will follow in a separate PR.

Introduced by b49ac69 ("nvmeofgw: fast-failover changes")

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

@evkuzin
evkuzin requested a review from a team as a code owner November 10, 2026 18:24
@github-actions

Copy link
Copy Markdown

Thank you for your contribution. Since you are not yet a member of the Ceph organization with write permissions on ceph/ceph.git, our CI will not automatically run. Any member of the Ceph organization may label this PR ci-approved to allow Jenkins CI jobs to run.

@tchaikov tchaikov 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.

lgtm

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been added to wip-bharath11-testing-20261114.052454-main.

@ronen-fr

Copy link
Copy Markdown
Contributor

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

@evkuzin Kindly address the PR check failure and proceed with merging the PR once the issue has been resolved. Should further QA validation be required, please re-add the needs-qa label and remove the TESTED label to facilitate retesting.

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