Repository navigation
[FIX] FeatureFinderAlgorithmPicked: count aborted seeds under a lock - #10546
Conversation
abort_() is called by all threads of the OpenMP seed extension in run_() and updated the member maps aborts_ (and, in debug mode, abort_reasons_ and the log) without a lock. Two threads inserting a new abort reason at the same time could corrupt the map, which crashed FeatureFinderAlgorithmPicked_test on macOS CI. The body of abort_() is now a named critical section, like the other shared state of the loop. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01B51nRFoHvZuVXD7cT8XZav
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Change: Bug fix Merge Risk: ⚪ Minimal · up to
|
|
Seems correct to me |
Description
FeatureFinderAlgorithmPicked::run_()extends seeds in a#pragma omp parallel forloop. It callsabort_()from three places in that loop when a seed fails (no isotope pattern, no extension, bad feature quality).abort_()updated the member mapaborts_with no lock, and in debug mode alsoabort_reasons_and the log. When two threads insert a new abort reason at the same time, they both rebalance the map's tree and can corrupt it.That crashed
FeatureFinderAlgorithmPicked_testwith a segfault on macOS CI (run on #10423, attempt 1; the re-run passed). The test section added in #10506 (min_isotope_fit,min_scoreandseed:min_scoreset to 0) rejects many seeds in parallel, which makes the collision more likely.The fix makes the body of
abort_()a named critical section, as the loop already does for its other shared state (_PLOTNR,_DEBUG,_TMPFEATUREMAP,_SEEDSINFEATURES).abort_()only counts the reason, so the lock is cheap compared with the trace extension and fitting around it. After the loop,run_()reads only the totals, and they don't depend on the order in which threads arrive.Not changed: with
debugon, otherlog_writes inside the loop (the seed output on the master thread,findBestIsotopeFit_) are still not synchronised. Debug mode is not used by the tests.Verification with helgrind
The crash did not reproduce locally: 30 runs with 16 threads before and after the fix passed. Helgrind is the evidence instead. It checks happens-before order, so it reports missing synchronisation even in runs where the threads don't actually collide.
Plain helgrind is useless on OpenMP code. libgomp synchronises with futexes that helgrind doesn't understand, so the unpatched test gives 231,657 reports from more than 1,000 contexts, most of them false positives. The runs below preload a small shim (below) that implements OpenMP critical sections with pthread mutexes and marks parallel fork/join and barriers as happens-before edges. They also suppress races whose accessing frame is inside libgomp itself. On a test program, the shim gives 0 reports for correctly locked code and reports exactly the unlocked line of a racy variant. Without the shim, helgrind also flags the line inside
omp critical.OMP_NUM_THREADS=4 LD_PRELOAD=libgomp_hg.so valgrind --tool=helgrind --suppressions=libgomp.supp FeatureFinderAlgorithmPicked_test(Linux, GCC 13.3, Debug, valgrind 3.22):513f9dd)abort_()as the accessing frame (aborts_insert andstd::_Rb_tree_insert_and_rebalance)The 2 other reports are
pthread_mutex_destroy with invalid argumentinlibp11-kitat program exit. They are not related to OpenMS.Tests:
FeatureFinderAlgorithmPicked_testand theTOPP_FeatureFinderCentroidedtests pass (7/7). The source file this PR changes and the test are identical to develop. I verified in a build tree of another branch with the same two files.libgomp_hg.c (LD_PRELOAD shim) and libgomp.supp
The shim covers the GOMP entry points that libOpenMS uses for parallel regions. Others (e.g.
GOMP_task, ordered loops) keep helgrind's usual false positives.Checklist
🤖 Generated with Claude Code
https://claude.ai/code/session_01B51nRFoHvZuVXD7cT8XZav
Generated by Claude Code
Summary by CodeRabbit