Skip to content

osd: Fix bugs with EC sync reads coroutine lifecycle - #71327

Merged
MattyWilliams22 merged 1 commit into
ceph:mainfrom
MattyWilliams22:wip-ec-sync-reads-memory-leak
Sep 22, 2026
Merged

MattyWilliams22 merged 1 commit into
ceph:mainfrom
MattyWilliams22:wip-ec-sync-reads-memory-leak

Conversation

@MattyWilliams22

@MattyWilliams22 MattyWilliams22 commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes: https://tracker.ceph.com/issues/79515

Valgrind encountered some memory leaks related to the coroutine that is used for synchronous reads in EC pools.

Bug 1: The coroutine lambda called coro_resumer = nullptr from inside its own body.
Fix: Instead, reset coro_resumer from the caller's stack immediately after `(*coro_resumer)() returns. Or reset it lazily at the top of do_op() during the next op.

Bug 2: use-after-free of resume token in the on_finish callback.
Fix: Have a shared pointer to the resume token. The callback derives a weak pointer and attempts to lock the weak pointer before resuming the coroutine. If on_change() already reset the resume token, the lock fails and the resume is skipped. The token is freed when the last shared pointer is released.

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

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)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@github-actions github-actions Bot added the core label Aug 25, 2026
@MattyWilliams22 MattyWilliams22 self-assigned this Aug 25, 2026

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

Generally LGTM.

Comment thread src/osd/ECBackend.cc Resolved
@MattyWilliams22
MattyWilliams22 force-pushed the wip-ec-sync-reads-memory-leak branch 2 times, most recently from 5ba6b43 to 94a6d2a Compare August 27, 2026 13:34
@MattyWilliams22

Copy link
Copy Markdown
Contributor Author

jenkins test windows

@MattyWilliams22

Copy link
Copy Markdown
Contributor Author

jenkins test api

@MattyWilliams22

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@MattyWilliams22

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

@MattyWilliams22
MattyWilliams22 marked this pull request as ready for review September 2, 2026 11:59
@MattyWilliams22
MattyWilliams22 requested a review from a team as a code owner September 2, 2026 11:59

@bill-scales bill-scales 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.

Agree that this fixes both the issues found by valgrind

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been added to wip-bharath10-testing-20260903.050751-main.

@amathuria

Copy link
Copy Markdown
Contributor

@MattyWilliams22 I am seeing a new failure in the test run - https://pulpito.ceph.com/skanta-2026-09-03_10:37:47-rados-wip-bharath10-testing-20260903.050751-main-distro-default-trial/534759/
osd.0 crashes with the following assert:

  -11> 2026-09-03T12:48:39.871+0000 7fc2f1e356c0 20 bluestore(/var/lib/ceph/osd/ceph-0) _kv_finalize_thread sleep
   -10> 2026-09-03T12:48:39.871+0000 7fc2e461a6c0 -1 osd.0 pg_epoch: 63 pg[4.6s0( v 62'5374 (0'0,62'5374] local-lis/les=61/62 n=1 ec=36/36 lis/c=61/61 les/c/f=62/62/0 sis=63) [7,1,2]p7(0) r=-1 lpr=63 pi=[61,63)/1 crt=62'5374 lcod 62'5373 unknown NOTIFY mbc={}] on_flushed: object 4:7089c203:MultiProducerConsumer%2fFastEC_1788439711305780051::virtual void TestCls2PCQueue_MultiProducerConsumer_Test%3a%3aTestBody():head obc still alive
    -9> 2026-09-03T12:48:39.872+0000 7fc3052246c0  1 -- v2:10.20.193.91:6801/3092977512 <== osd.3 v2:10.20.193.91:6813/1990943167 7624 ==== pg_query2(3.18 3.18 query(info 0'0 epoch_sent 63) e63/63) ==== 158+0+0 (unknown 0 0 0) 0x5562fda174a0 con 0x5562fbfabc00
    -8> 2026-09-03T12:48:39.872+0000 7fc2e76206c0  1 -- v2:10.20.193.91:6801/3092977512 --> v2:10.20.193.91:6813/1990943167 -- pg_notify2(3.18 3.18 (query:63 sent:63 3.18( empty local-lis/les=37/38 n=0 ec=32/32 lis/c=37/37 les/c/f=38/38/0 sis=63 pruub=15.184741974s) ([37,62] all_participants={0, 3} intervals=[([37,62] acting={0, 3})])) e63/63) -- 0x5562fdaa6000 con 0x5562fbfabc00
    -7> 2026-09-03T12:48:39.872+0000 7fc2f2b906c0  1 -- v2:10.20.193.91:6801/3092977512 <== osd.3 v2:10.20.193.91:6813/1990943167 7625 ==== osd_map(62..63 src has 1..63) ==== 1037+0+0 (unknown 0 0 0) 0x55630029aa80 con 0x5562fbfabc00
    -6> 2026-09-03T12:48:39.872+0000 7fc2f2b906c0  3 osd.0 63 handle_osd_map epochs [62,63], i have 63, src has [1,63]
    -5> 2026-09-03T12:48:39.872+0000 7fc2e461a6c0 -1 /ceph/rpmbuild/BUILD/ceph-21.3.0-2737-g2aa7d19c/src/osd/PrimaryLogPG.cc: In function 'virtual void PrimaryLogPG::on_flushed()' thread 7fc2e461a6c0 time 2026-09-03T12:48:39.871970+0000
/ceph/rpmbuild/BUILD/ceph-21.3.0-2737-g2aa7d19c/src/osd/PrimaryLogPG.cc: 13205: FAILED ceph_assert(object_contexts.empty())

I think it might be related, could you check it out?

…ange

Bug 1: The coroutine lambda called `coro_resumer = nullptr` from inside its own body.
Fix: Instead, reset coro_resumer from the caller's stack immediately after `(*coro_resumer)() returns. Or reset it lazily at the top of do_op() during the next op.

Bug 2: use-after-free of resume token in the on_finish callback.
Fix: Have a shared pointer to the resume token. The callback derives a weak pointer and attempts to lock the weak pointer before resuming the coroutine. If on_change() already reset the resume token, the lock fails and the resume is skipped. The token is freed when the last shared pointer is released.

Fixes: https://tracker.ceph.com/issues/79515
Signed-off-by: Matty Williams <[email protected]>
Assisted-by: IBM-Bob-2.0.2:Claude/GPT
@MattyWilliams22
MattyWilliams22 force-pushed the wip-ec-sync-reads-memory-leak branch from 94a6d2a to 94103bb Compare September 9, 2026 13:10
@MattyWilliams22

Copy link
Copy Markdown
Contributor Author

I believe this issue is related and I have recreated it locally on this branch.

I have pushed a fix which is working locally.

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been added to wip-bharath10-testing-20260910.230227-main.

@connorfawcett

Copy link
Copy Markdown
Contributor

@MattyWilliams22
MattyWilliams22 merged commit 787a82e into ceph:main Sep 22, 2026
15 checks passed
@MattyWilliams22
MattyWilliams22 deleted the wip-ec-sync-reads-memory-leak branch September 22, 2026 15:02
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.

6 participants