* [ruby-core:122121] [Ruby Bug#21342] Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC
@ 2025-05-15 16:44 maciej.mensfeld (Maciej Mensfeld) via ruby-core
2025-05-15 17:14 ` [ruby-core:122122] " masterleep2 (Bill Lipa) via ruby-core
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: maciej.mensfeld (Maciej Mensfeld) via ruby-core @ 2025-05-15 16:44 UTC (permalink / raw)
To: ruby-core; +Cc: maciej.mensfeld (Maciej Mensfeld)
Issue #21342 has been reported by maciej.mensfeld (Maciej Mensfeld).
----------------------------------------
Bug #21342: Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC
https://bugs.ruby-lang.org/issues/21342
* Author: maciej.mensfeld (Maciej Mensfeld)
* Status: Open
* ruby -v: 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
Ruby crashes with a `[BUG] invalid keeping_mutexes error` when attempting to GC locked mutex that was used in a Thread within a Fiber context after garbage collection. The error indicates an attempt to unlock a mutex that is not locked, suggesting a state management issue with mutexes across Thread and Fiber boundaries.
## Ruby Version
`ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]`
## Reproduce Process
``` ruby
# segv.rb
5.times do
m = Mutex.new
Thread.new do
m.synchronize do
end
end.join
Fiber.new do
GC.start
m.lock
end.resume
end
```
1. Save the above code to a file (e.g., `segv.rb`)
2. Run with `ruby segv.rb`
3. The crash occurs intermittently - sometimes it crashes immediately, sometimes it hangs, once in a while it works
## Actual Result
The program crashes with the following error:
```
segv.rb: [BUG] invalid keeping_mutexes: Attempt to unlock a mutex which is not locked
ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]
```
whole segfault in the attached txt file.
Full crash backtrace shows the error originates from:
- `rb_threadptr_unlock_all_locking_mutexes` in thread.c:450
- `rb_thread_terminate_all` in thread.c:467
The crash suggests an issue in mutex state management during thread termination.
## Expected Result
The script should complete successfully without crashing. The mutex should be properly managed across Thread and Fiber contexts, and garbage collection should not interfere with mutex state.
---Files--------------------------------
crash.txt (23.4 KB)
--
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/
^ permalink raw reply [flat|nested] 11+ messages in thread
* [ruby-core:122122] [Ruby Bug#21342] Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC
2025-05-15 16:44 [ruby-core:122121] [Ruby Bug#21342] Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC maciej.mensfeld (Maciej Mensfeld) via ruby-core
@ 2025-05-15 17:14 ` masterleep2 (Bill Lipa) via ruby-core
2025-05-15 17:52 ` [ruby-core:122123] " byroot (Jean Boussier) via ruby-core
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: masterleep2 (Bill Lipa) via ruby-core @ 2025-05-15 17:14 UTC (permalink / raw)
To: ruby-core; +Cc: masterleep2 (Bill Lipa)
Issue #21342 has been updated by masterleep2 (Bill Lipa).
Additionally, on macOS, the script crashes but then gets in a seemingly endless loop after printing the 'C level backtrace information' line, and can't be killed with ^C.
----------------------------------------
Bug #21342: Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC
https://bugs.ruby-lang.org/issues/21342#change-113275
* Author: maciej.mensfeld (Maciej Mensfeld)
* Status: Open
* ruby -v: 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
Ruby crashes with a `[BUG] invalid keeping_mutexes error` when attempting to GC locked mutex that was used in a Thread within a Fiber context after garbage collection. The error indicates an attempt to unlock a mutex that is not locked, suggesting a state management issue with mutexes across Thread and Fiber boundaries.
## Ruby Version
`ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]`
## Reproduce Process
``` ruby
# segv.rb
5.times do
m = Mutex.new
Thread.new do
m.synchronize do
end
end.join
Fiber.new do
GC.start
m.lock
end.resume
end
```
1. Save the above code to a file (e.g., `segv.rb`)
2. Run with `ruby segv.rb`
3. The crash occurs intermittently - sometimes it crashes immediately, sometimes it hangs, once in a while it works
## Actual Result
The program crashes with the following error:
```
segv.rb: [BUG] invalid keeping_mutexes: Attempt to unlock a mutex which is not locked
ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]
```
whole segfault in the attached txt file.
Full crash backtrace shows the error originates from:
- `rb_threadptr_unlock_all_locking_mutexes` in thread.c:450
- `rb_thread_terminate_all` in thread.c:467
The crash suggests an issue in mutex state management during thread termination.
## Expected Result
The script should complete successfully without crashing. The mutex should be properly managed across Thread and Fiber contexts, and garbage collection should not interfere with mutex state.
---Files--------------------------------
crash.txt (23.4 KB)
--
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/
^ permalink raw reply [flat|nested] 11+ messages in thread
* [ruby-core:122123] [Ruby Bug#21342] Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC
2025-05-15 16:44 [ruby-core:122121] [Ruby Bug#21342] Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC maciej.mensfeld (Maciej Mensfeld) via ruby-core
2025-05-15 17:14 ` [ruby-core:122122] " masterleep2 (Bill Lipa) via ruby-core
@ 2025-05-15 17:52 ` byroot (Jean Boussier) via ruby-core
2025-05-15 18:06 ` [ruby-core:122124] " byroot (Jean Boussier) via ruby-core
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: byroot (Jean Boussier) via ruby-core @ 2025-05-15 17:52 UTC (permalink / raw)
To: ruby-core; +Cc: byroot (Jean Boussier)
Issue #21342 has been updated by byroot (Jean Boussier).
Looks like we're missing a null check:
```
* frame #0: 0x0000000100349cb4 miniruby`thread_mutex_remove(thread=0x0000000000000000, mutex=0x0000600001147f00) at thread_sync.c:225:12
frame #1: 0x000000010033c1f0 miniruby`rb_mutex_unlock_th(mutex=0x0000600001147f00, th=0x0000000000000000, fiber=0x0000000122f0a9c0) at thread_sync.c:467:5
frame #2: 0x0000000100349a9c miniruby`mutex_free(ptr=0x0000600001147f00) at thread_sync.c:132:27
frame #3: 0x0000000100122bdc miniruby`rb_data_free(objspace=0x000000012380a200, obj=4349174720) at gc.c:1192:17
frame #4: 0x0000000100122638 miniruby`rb_gc_obj_free(objspace=0x000000012380a200, obj=4349174720) at gc.c:1371:14
```
I suspec tthe thread was freed before the mutex.
----------------------------------------
Bug #21342: Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC
https://bugs.ruby-lang.org/issues/21342#change-113276
* Author: maciej.mensfeld (Maciej Mensfeld)
* Status: Open
* ruby -v: 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
Ruby crashes with a `[BUG] invalid keeping_mutexes error` when attempting to GC locked mutex that was used in a Thread within a Fiber context after garbage collection. The error indicates an attempt to unlock a mutex that is not locked, suggesting a state management issue with mutexes across Thread and Fiber boundaries.
## Ruby Version
`ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]`
## Reproduce Process
``` ruby
# segv.rb
5.times do
m = Mutex.new
Thread.new do
m.synchronize do
end
end.join
Fiber.new do
GC.start
m.lock
end.resume
end
```
1. Save the above code to a file (e.g., `segv.rb`)
2. Run with `ruby segv.rb`
3. The crash occurs intermittently - sometimes it crashes immediately, sometimes it hangs, once in a while it works
## Actual Result
The program crashes with the following error:
```
segv.rb: [BUG] invalid keeping_mutexes: Attempt to unlock a mutex which is not locked
ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]
```
whole segfault in the attached txt file.
Full crash backtrace shows the error originates from:
- `rb_threadptr_unlock_all_locking_mutexes` in thread.c:450
- `rb_thread_terminate_all` in thread.c:467
The crash suggests an issue in mutex state management during thread termination.
## Expected Result
The script should complete successfully without crashing. The mutex should be properly managed across Thread and Fiber contexts, and garbage collection should not interfere with mutex state.
---Files--------------------------------
crash.txt (23.4 KB)
--
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/
^ permalink raw reply [flat|nested] 11+ messages in thread
* [ruby-core:122124] [Ruby Bug#21342] Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC
2025-05-15 16:44 [ruby-core:122121] [Ruby Bug#21342] Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC maciej.mensfeld (Maciej Mensfeld) via ruby-core
2025-05-15 17:14 ` [ruby-core:122122] " masterleep2 (Bill Lipa) via ruby-core
2025-05-15 17:52 ` [ruby-core:122123] " byroot (Jean Boussier) via ruby-core
@ 2025-05-15 18:06 ` byroot (Jean Boussier) via ruby-core
2025-08-18 17:49 ` [ruby-core:122979] " luke-gru (Luke Gruber) via ruby-core
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: byroot (Jean Boussier) via ruby-core @ 2025-05-15 18:06 UTC (permalink / raw)
To: ruby-core; +Cc: byroot (Jean Boussier)
Issue #21342 has been updated by byroot (Jean Boussier).
Looks like it's not that simple. This smells of memory corruption because we end up in this loop:
```c
-> 230 while (*keeping_mutexes && *keeping_mutexes != mutex) {
231 // Move to the next mutex in the list:
232 keeping_mutexes = &(*keeping_mutexes)->next_mutex;
233 }
```
And at some point `->next_mutex` is a clearly wrong pointer (various low values such as `0xff`, `0x13`, etc). So I assume something else end up overwriting that memory.
All I can say is it still reproduce on `master`.
----------------------------------------
Bug #21342: Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC
https://bugs.ruby-lang.org/issues/21342#change-113277
* Author: maciej.mensfeld (Maciej Mensfeld)
* Status: Open
* ruby -v: 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
Ruby crashes with a `[BUG] invalid keeping_mutexes error` when attempting to GC locked mutex that was used in a Thread within a Fiber context after garbage collection. The error indicates an attempt to unlock a mutex that is not locked, suggesting a state management issue with mutexes across Thread and Fiber boundaries.
## Ruby Version
`ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]`
## Reproduce Process
``` ruby
# segv.rb
5.times do
m = Mutex.new
Thread.new do
m.synchronize do
end
end.join
Fiber.new do
GC.start
m.lock
end.resume
end
```
1. Save the above code to a file (e.g., `segv.rb`)
2. Run with `ruby segv.rb`
3. The crash occurs intermittently - sometimes it crashes immediately, sometimes it hangs, once in a while it works
## Actual Result
The program crashes with the following error:
```
segv.rb: [BUG] invalid keeping_mutexes: Attempt to unlock a mutex which is not locked
ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]
```
whole segfault in the attached txt file.
Full crash backtrace shows the error originates from:
- `rb_threadptr_unlock_all_locking_mutexes` in thread.c:450
- `rb_thread_terminate_all` in thread.c:467
The crash suggests an issue in mutex state management during thread termination.
## Expected Result
The script should complete successfully without crashing. The mutex should be properly managed across Thread and Fiber contexts, and garbage collection should not interfere with mutex state.
---Files--------------------------------
crash.txt (23.4 KB)
--
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/
^ permalink raw reply [flat|nested] 11+ messages in thread
* [ruby-core:122979] [Ruby Bug#21342] Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC
2025-05-15 16:44 [ruby-core:122121] [Ruby Bug#21342] Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC maciej.mensfeld (Maciej Mensfeld) via ruby-core
` (2 preceding siblings ...)
2025-05-15 18:06 ` [ruby-core:122124] " byroot (Jean Boussier) via ruby-core
@ 2025-08-18 17:49 ` luke-gru (Luke Gruber) via ruby-core
2025-08-30 0:54 ` [ruby-core:123132] " ioquatix (Samuel Williams) via ruby-core
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: luke-gru (Luke Gruber) via ruby-core @ 2025-08-18 17:49 UTC (permalink / raw)
To: ruby-core; +Cc: luke-gru (Luke Gruber)
Issue #21342 has been updated by luke-gru (Luke Gruber).
Backport changed from 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN to 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: REQUIRED
I created a PR here: https://github.com/ruby/ruby/pull/14262
----------------------------------------
Bug #21342: Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC
https://bugs.ruby-lang.org/issues/21342#change-114282
* Author: maciej.mensfeld (Maciej Mensfeld)
* Status: Open
* ruby -v: 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: REQUIRED
----------------------------------------
Ruby crashes with a `[BUG] invalid keeping_mutexes error` when attempting to GC locked mutex that was used in a Thread within a Fiber context after garbage collection. The error indicates an attempt to unlock a mutex that is not locked, suggesting a state management issue with mutexes across Thread and Fiber boundaries.
## Ruby Version
`ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]`
## Reproduce Process
``` ruby
# segv.rb
5.times do
m = Mutex.new
Thread.new do
m.synchronize do
end
end.join
Fiber.new do
GC.start
m.lock
end.resume
end
```
1. Save the above code to a file (e.g., `segv.rb`)
2. Run with `ruby segv.rb`
3. The crash occurs intermittently - sometimes it crashes immediately, sometimes it hangs, once in a while it works
## Actual Result
The program crashes with the following error:
```
segv.rb: [BUG] invalid keeping_mutexes: Attempt to unlock a mutex which is not locked
ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]
```
whole segfault in the attached txt file.
Full crash backtrace shows the error originates from:
- `rb_threadptr_unlock_all_locking_mutexes` in thread.c:450
- `rb_thread_terminate_all` in thread.c:467
The crash suggests an issue in mutex state management during thread termination.
## Expected Result
The script should complete successfully without crashing. The mutex should be properly managed across Thread and Fiber contexts, and garbage collection should not interfere with mutex state.
---Files--------------------------------
crash.txt (23.4 KB)
--
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/
^ permalink raw reply [flat|nested] 11+ messages in thread
* [ruby-core:123132] [Ruby Bug#21342] Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC
2025-05-15 16:44 [ruby-core:122121] [Ruby Bug#21342] Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC maciej.mensfeld (Maciej Mensfeld) via ruby-core
` (3 preceding siblings ...)
2025-08-18 17:49 ` [ruby-core:122979] " luke-gru (Luke Gruber) via ruby-core
@ 2025-08-30 0:54 ` ioquatix (Samuel Williams) via ruby-core
2025-09-29 21:35 ` [ruby-core:123341] " k0kubun (Takashi Kokubun) via ruby-core
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: ioquatix (Samuel Williams) via ruby-core @ 2025-08-30 0:54 UTC (permalink / raw)
To: ruby-core; +Cc: ioquatix (Samuel Williams)
Issue #21342 has been updated by ioquatix (Samuel Williams).
Just for the sake of cross-referencing related issues: https://bugs.ruby-lang.org/issues/18818
----------------------------------------
Bug #21342: Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC
https://bugs.ruby-lang.org/issues/21342#change-114459
* Author: maciej.mensfeld (Maciej Mensfeld)
* Status: Open
* ruby -v: 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]
* Backport: 3.2: UNKNOWN, 3.3: REQUIRED, 3.4: REQUIRED
----------------------------------------
Ruby crashes with a `[BUG] invalid keeping_mutexes error` when attempting to GC locked mutex that was used in a Thread within a Fiber context after garbage collection. The error indicates an attempt to unlock a mutex that is not locked, suggesting a state management issue with mutexes across Thread and Fiber boundaries.
## Ruby Version
`ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]`
## Reproduce Process
``` ruby
# segv.rb
5.times do
m = Mutex.new
Thread.new do
m.synchronize do
end
end.join
Fiber.new do
GC.start
m.lock
end.resume
end
```
1. Save the above code to a file (e.g., `segv.rb`)
2. Run with `ruby segv.rb`
3. The crash occurs intermittently - sometimes it crashes immediately, sometimes it hangs, once in a while it works
## Actual Result
The program crashes with the following error:
```
segv.rb: [BUG] invalid keeping_mutexes: Attempt to unlock a mutex which is not locked
ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]
```
whole segfault in the attached txt file.
Full crash backtrace shows the error originates from:
- `rb_threadptr_unlock_all_locking_mutexes` in thread.c:450
- `rb_thread_terminate_all` in thread.c:467
The crash suggests an issue in mutex state management during thread termination.
## Expected Result
The script should complete successfully without crashing. The mutex should be properly managed across Thread and Fiber contexts, and garbage collection should not interfere with mutex state.
---Files--------------------------------
crash.txt (23.4 KB)
--
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/
^ permalink raw reply [flat|nested] 11+ messages in thread
* [ruby-core:123341] [Ruby Bug#21342] Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC
2025-05-15 16:44 [ruby-core:122121] [Ruby Bug#21342] Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC maciej.mensfeld (Maciej Mensfeld) via ruby-core
` (4 preceding siblings ...)
2025-08-30 0:54 ` [ruby-core:123132] " ioquatix (Samuel Williams) via ruby-core
@ 2025-09-29 21:35 ` k0kubun (Takashi Kokubun) via ruby-core
2025-09-29 22:09 ` [ruby-core:123343] " k0kubun (Takashi Kokubun) via ruby-core
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: k0kubun (Takashi Kokubun) via ruby-core @ 2025-09-29 21:35 UTC (permalink / raw)
To: ruby-core; +Cc: k0kubun (Takashi Kokubun)
Issue #21342 has been updated by k0kubun (Takashi Kokubun).
Backport changed from 3.2: UNKNOWN, 3.3: REQUIRED, 3.4: REQUIRED to 3.2: UNKNOWN, 3.3: REQUIRED, 3.4: DONE
ruby_3_4 commit:4306c9048fb674d24b92dc46b6746a4749564147 merged revision(s) commit:62430c19c9f1ab49429cebe65f30588472648c95.
----------------------------------------
Bug #21342: Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC
https://bugs.ruby-lang.org/issues/21342#change-114713
* Author: maciej.mensfeld (Maciej Mensfeld)
* Status: Closed
* ruby -v: 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]
* Backport: 3.2: UNKNOWN, 3.3: REQUIRED, 3.4: DONE
----------------------------------------
Ruby crashes with a `[BUG] invalid keeping_mutexes error` when attempting to GC locked mutex that was used in a Thread within a Fiber context after garbage collection. The error indicates an attempt to unlock a mutex that is not locked, suggesting a state management issue with mutexes across Thread and Fiber boundaries.
## Ruby Version
`ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]`
## Reproduce Process
``` ruby
# segv.rb
5.times do
m = Mutex.new
Thread.new do
m.synchronize do
end
end.join
Fiber.new do
GC.start
m.lock
end.resume
end
```
1. Save the above code to a file (e.g., `segv.rb`)
2. Run with `ruby segv.rb`
3. The crash occurs intermittently - sometimes it crashes immediately, sometimes it hangs, once in a while it works
## Actual Result
The program crashes with the following error:
```
segv.rb: [BUG] invalid keeping_mutexes: Attempt to unlock a mutex which is not locked
ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]
```
whole segfault in the attached txt file.
Full crash backtrace shows the error originates from:
- `rb_threadptr_unlock_all_locking_mutexes` in thread.c:450
- `rb_thread_terminate_all` in thread.c:467
The crash suggests an issue in mutex state management during thread termination.
## Expected Result
The script should complete successfully without crashing. The mutex should be properly managed across Thread and Fiber contexts, and garbage collection should not interfere with mutex state.
---Files--------------------------------
crash.txt (23.4 KB)
--
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/
^ permalink raw reply [flat|nested] 11+ messages in thread
* [ruby-core:123343] [Ruby Bug#21342] Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC
2025-05-15 16:44 [ruby-core:122121] [Ruby Bug#21342] Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC maciej.mensfeld (Maciej Mensfeld) via ruby-core
` (5 preceding siblings ...)
2025-09-29 21:35 ` [ruby-core:123341] " k0kubun (Takashi Kokubun) via ruby-core
@ 2025-09-29 22:09 ` k0kubun (Takashi Kokubun) via ruby-core
2025-09-29 22:10 ` [ruby-core:123344] " k0kubun (Takashi Kokubun) via ruby-core
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: k0kubun (Takashi Kokubun) via ruby-core @ 2025-09-29 22:09 UTC (permalink / raw)
To: ruby-core; +Cc: k0kubun (Takashi Kokubun)
Issue #21342 has been updated by k0kubun (Takashi Kokubun).
Backport changed from 3.2: UNKNOWN, 3.3: REQUIRED, 3.4: DONE to 3.2: UNKNOWN, 3.3: REQUIRED, 3.4: REQUIRED
Reverted the ruby_3_4 backport since it failed the CI.
----------------------------------------
Bug #21342: Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC
https://bugs.ruby-lang.org/issues/21342#change-114715
* Author: maciej.mensfeld (Maciej Mensfeld)
* Status: Closed
* ruby -v: 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]
* Backport: 3.2: UNKNOWN, 3.3: REQUIRED, 3.4: REQUIRED
----------------------------------------
Ruby crashes with a `[BUG] invalid keeping_mutexes error` when attempting to GC locked mutex that was used in a Thread within a Fiber context after garbage collection. The error indicates an attempt to unlock a mutex that is not locked, suggesting a state management issue with mutexes across Thread and Fiber boundaries.
## Ruby Version
`ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]`
## Reproduce Process
``` ruby
# segv.rb
5.times do
m = Mutex.new
Thread.new do
m.synchronize do
end
end.join
Fiber.new do
GC.start
m.lock
end.resume
end
```
1. Save the above code to a file (e.g., `segv.rb`)
2. Run with `ruby segv.rb`
3. The crash occurs intermittently - sometimes it crashes immediately, sometimes it hangs, once in a while it works
## Actual Result
The program crashes with the following error:
```
segv.rb: [BUG] invalid keeping_mutexes: Attempt to unlock a mutex which is not locked
ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]
```
whole segfault in the attached txt file.
Full crash backtrace shows the error originates from:
- `rb_threadptr_unlock_all_locking_mutexes` in thread.c:450
- `rb_thread_terminate_all` in thread.c:467
The crash suggests an issue in mutex state management during thread termination.
## Expected Result
The script should complete successfully without crashing. The mutex should be properly managed across Thread and Fiber contexts, and garbage collection should not interfere with mutex state.
---Files--------------------------------
crash.txt (23.4 KB)
--
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/
^ permalink raw reply [flat|nested] 11+ messages in thread
* [ruby-core:123344] [Ruby Bug#21342] Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC
2025-05-15 16:44 [ruby-core:122121] [Ruby Bug#21342] Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC maciej.mensfeld (Maciej Mensfeld) via ruby-core
` (6 preceding siblings ...)
2025-09-29 22:09 ` [ruby-core:123343] " k0kubun (Takashi Kokubun) via ruby-core
@ 2025-09-29 22:10 ` k0kubun (Takashi Kokubun) via ruby-core
2025-09-29 22:11 ` [ruby-core:123345] " k0kubun (Takashi Kokubun) via ruby-core
2025-10-05 10:11 ` [ruby-core:123396] " nagachika (Tomoyuki Chikanaga) via ruby-core
9 siblings, 0 replies; 11+ messages in thread
From: k0kubun (Takashi Kokubun) via ruby-core @ 2025-09-29 22:10 UTC (permalink / raw)
To: ruby-core; +Cc: k0kubun (Takashi Kokubun)
Issue #21342 has been updated by k0kubun (Takashi Kokubun).
I guess it was due to a wrong conflict resolution. I'll attempt to backport it again.
----------------------------------------
Bug #21342: Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC
https://bugs.ruby-lang.org/issues/21342#change-114716
* Author: maciej.mensfeld (Maciej Mensfeld)
* Status: Closed
* ruby -v: 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]
* Backport: 3.2: UNKNOWN, 3.3: REQUIRED, 3.4: REQUIRED
----------------------------------------
Ruby crashes with a `[BUG] invalid keeping_mutexes error` when attempting to GC locked mutex that was used in a Thread within a Fiber context after garbage collection. The error indicates an attempt to unlock a mutex that is not locked, suggesting a state management issue with mutexes across Thread and Fiber boundaries.
## Ruby Version
`ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]`
## Reproduce Process
``` ruby
# segv.rb
5.times do
m = Mutex.new
Thread.new do
m.synchronize do
end
end.join
Fiber.new do
GC.start
m.lock
end.resume
end
```
1. Save the above code to a file (e.g., `segv.rb`)
2. Run with `ruby segv.rb`
3. The crash occurs intermittently - sometimes it crashes immediately, sometimes it hangs, once in a while it works
## Actual Result
The program crashes with the following error:
```
segv.rb: [BUG] invalid keeping_mutexes: Attempt to unlock a mutex which is not locked
ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]
```
whole segfault in the attached txt file.
Full crash backtrace shows the error originates from:
- `rb_threadptr_unlock_all_locking_mutexes` in thread.c:450
- `rb_thread_terminate_all` in thread.c:467
The crash suggests an issue in mutex state management during thread termination.
## Expected Result
The script should complete successfully without crashing. The mutex should be properly managed across Thread and Fiber contexts, and garbage collection should not interfere with mutex state.
---Files--------------------------------
crash.txt (23.4 KB)
--
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/
^ permalink raw reply [flat|nested] 11+ messages in thread
* [ruby-core:123345] [Ruby Bug#21342] Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC
2025-05-15 16:44 [ruby-core:122121] [Ruby Bug#21342] Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC maciej.mensfeld (Maciej Mensfeld) via ruby-core
` (7 preceding siblings ...)
2025-09-29 22:10 ` [ruby-core:123344] " k0kubun (Takashi Kokubun) via ruby-core
@ 2025-09-29 22:11 ` k0kubun (Takashi Kokubun) via ruby-core
2025-10-05 10:11 ` [ruby-core:123396] " nagachika (Tomoyuki Chikanaga) via ruby-core
9 siblings, 0 replies; 11+ messages in thread
From: k0kubun (Takashi Kokubun) via ruby-core @ 2025-09-29 22:11 UTC (permalink / raw)
To: ruby-core; +Cc: k0kubun (Takashi Kokubun)
Issue #21342 has been updated by k0kubun (Takashi Kokubun).
Backport changed from 3.2: UNKNOWN, 3.3: REQUIRED, 3.4: REQUIRED to 3.2: UNKNOWN, 3.3: REQUIRED, 3.4: DONE
ruby_3_4 commit:264b2d78c366491834c9ce4499a4ad7b7564b89d.
----------------------------------------
Bug #21342: Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC
https://bugs.ruby-lang.org/issues/21342#change-114717
* Author: maciej.mensfeld (Maciej Mensfeld)
* Status: Closed
* ruby -v: 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]
* Backport: 3.2: UNKNOWN, 3.3: REQUIRED, 3.4: DONE
----------------------------------------
Ruby crashes with a `[BUG] invalid keeping_mutexes error` when attempting to GC locked mutex that was used in a Thread within a Fiber context after garbage collection. The error indicates an attempt to unlock a mutex that is not locked, suggesting a state management issue with mutexes across Thread and Fiber boundaries.
## Ruby Version
`ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]`
## Reproduce Process
``` ruby
# segv.rb
5.times do
m = Mutex.new
Thread.new do
m.synchronize do
end
end.join
Fiber.new do
GC.start
m.lock
end.resume
end
```
1. Save the above code to a file (e.g., `segv.rb`)
2. Run with `ruby segv.rb`
3. The crash occurs intermittently - sometimes it crashes immediately, sometimes it hangs, once in a while it works
## Actual Result
The program crashes with the following error:
```
segv.rb: [BUG] invalid keeping_mutexes: Attempt to unlock a mutex which is not locked
ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]
```
whole segfault in the attached txt file.
Full crash backtrace shows the error originates from:
- `rb_threadptr_unlock_all_locking_mutexes` in thread.c:450
- `rb_thread_terminate_all` in thread.c:467
The crash suggests an issue in mutex state management during thread termination.
## Expected Result
The script should complete successfully without crashing. The mutex should be properly managed across Thread and Fiber contexts, and garbage collection should not interfere with mutex state.
---Files--------------------------------
crash.txt (23.4 KB)
--
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/
^ permalink raw reply [flat|nested] 11+ messages in thread
* [ruby-core:123396] [Ruby Bug#21342] Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC
2025-05-15 16:44 [ruby-core:122121] [Ruby Bug#21342] Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC maciej.mensfeld (Maciej Mensfeld) via ruby-core
` (8 preceding siblings ...)
2025-09-29 22:11 ` [ruby-core:123345] " k0kubun (Takashi Kokubun) via ruby-core
@ 2025-10-05 10:11 ` nagachika (Tomoyuki Chikanaga) via ruby-core
9 siblings, 0 replies; 11+ messages in thread
From: nagachika (Tomoyuki Chikanaga) via ruby-core @ 2025-10-05 10:11 UTC (permalink / raw)
To: ruby-core; +Cc: nagachika (Tomoyuki Chikanaga)
Issue #21342 has been updated by nagachika (Tomoyuki Chikanaga).
Backport changed from 3.2: UNKNOWN, 3.3: REQUIRED, 3.4: DONE to 3.2: UNKNOWN, 3.3: DONE, 3.4: DONE
ruby_3_3 commit:05f93fe6dc6f99fd2f728dd3c85dca944f1f4ba1 merged revision(s) commit:62430c19c9f1ab49429cebe65f30588472648c95.
----------------------------------------
Bug #21342: Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC
https://bugs.ruby-lang.org/issues/21342#change-114767
* Author: maciej.mensfeld (Maciej Mensfeld)
* Status: Closed
* ruby -v: 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]
* Backport: 3.2: UNKNOWN, 3.3: DONE, 3.4: DONE
----------------------------------------
Ruby crashes with a `[BUG] invalid keeping_mutexes error` when attempting to GC locked mutex that was used in a Thread within a Fiber context after garbage collection. The error indicates an attempt to unlock a mutex that is not locked, suggesting a state management issue with mutexes across Thread and Fiber boundaries.
## Ruby Version
`ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]`
## Reproduce Process
``` ruby
# segv.rb
5.times do
m = Mutex.new
Thread.new do
m.synchronize do
end
end.join
Fiber.new do
GC.start
m.lock
end.resume
end
```
1. Save the above code to a file (e.g., `segv.rb`)
2. Run with `ruby segv.rb`
3. The crash occurs intermittently - sometimes it crashes immediately, sometimes it hangs, once in a while it works
## Actual Result
The program crashes with the following error:
```
segv.rb: [BUG] invalid keeping_mutexes: Attempt to unlock a mutex which is not locked
ruby 3.4.3 (2025-04-14 revision d0b7e5b6a0) +PRISM [x86_64-linux]
```
whole segfault in the attached txt file.
Full crash backtrace shows the error originates from:
- `rb_threadptr_unlock_all_locking_mutexes` in thread.c:450
- `rb_thread_terminate_all` in thread.c:467
The crash suggests an issue in mutex state management during thread termination.
## Expected Result
The script should complete successfully without crashing. The mutex should be properly managed across Thread and Fiber contexts, and garbage collection should not interfere with mutex state.
---Files--------------------------------
crash.txt (23.4 KB)
--
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/
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2025-10-05 10:12 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-15 16:44 [ruby-core:122121] [Ruby Bug#21342] Segfault: invalid keeping_mutexes when using Mutex in Thread then Fiber after GC maciej.mensfeld (Maciej Mensfeld) via ruby-core
2025-05-15 17:14 ` [ruby-core:122122] " masterleep2 (Bill Lipa) via ruby-core
2025-05-15 17:52 ` [ruby-core:122123] " byroot (Jean Boussier) via ruby-core
2025-05-15 18:06 ` [ruby-core:122124] " byroot (Jean Boussier) via ruby-core
2025-08-18 17:49 ` [ruby-core:122979] " luke-gru (Luke Gruber) via ruby-core
2025-08-30 0:54 ` [ruby-core:123132] " ioquatix (Samuel Williams) via ruby-core
2025-09-29 21:35 ` [ruby-core:123341] " k0kubun (Takashi Kokubun) via ruby-core
2025-09-29 22:09 ` [ruby-core:123343] " k0kubun (Takashi Kokubun) via ruby-core
2025-09-29 22:10 ` [ruby-core:123344] " k0kubun (Takashi Kokubun) via ruby-core
2025-09-29 22:11 ` [ruby-core:123345] " k0kubun (Takashi Kokubun) via ruby-core
2025-10-05 10:11 ` [ruby-core:123396] " nagachika (Tomoyuki Chikanaga) via ruby-core
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).