From: "jhawthorn (John Hawthorn) via ruby-core" Date: 2026-11-18T04:31:18+00:00 Subject: [ruby-core:127568] [Ruby Bug#22598] A thread that ends holding two mutexes corrupts the next owner's mutex list Issue #22598 has been reported by jhawthorn (John Hawthorn). ---------------------------------------- Bug #22598: A thread that ends holding two mutexes corrupts the next owner's mutex list https://bugs.ruby-lang.org/issues/22598 * Author: jhawthorn (John Hawthorn) * Status: Open * ruby -v: ruby 4.0.9 (2026-10-23 revision 3e93b23afc) +PRISM [x86_64-linux] * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: REQUIRED ---------------------------------------- Reproduces on 4.0.9 and master: ```ruby m1 = Thread::Mutex.new m2 = Thread::Mutex.new Thread.new { m1.lock; m2.lock }.join Thread.new { m2.synchronize { } }.join # [BUG] invalid keeping_mutexes: Attempt to unlock a mutex which is not locked ``` When a thread exits, `rb_threadptr_unlock_all_locking_mutexes` pops each mutex off `th->keeping_mutexes` before unlocking it, so `rb_mutex_unlock_th` never clears its `next_mutex`. The next thread to lock `m2` inherits `m1` in its list and unlocks it when it exits, which crashes if `m1` is unlocked, releases it out from under another thread if it's locked, and is a use after free if it's been collected. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/