Repository navigation
Keep TracePoint event data per thread instead of locking the hook - #10102
Open
sampokuokkanen wants to merge 1 commit into
Open
sampokuokkanen wants to merge 1 commit into
sampokuokkanen wants to merge 1 commit into
Conversation
A TracePoint's hook held a lock while its block ran, because the event data was stored on the TracePoint object. When a hook stopped and waited for another thread, and that thread hit the same TracePoint, both threads hung. The debug gem does this: it stops inside a breakpoint's hook and waits for its session thread, which runs Ruby code that the same TracePoint traces. The event data is now kept on the thread while the hook runs, and the hook no longer takes a lock. This follows CRuby, which keeps the trace argument per execution context. As in CRuby, a TracePoint's attributes read the event of the hook running on the current thread, and TracePoint#self now raises "access from outside" outside a hook like the other attributes. The hook of one TracePoint can now run on several threads at once, as set_trace_func hooks already could, and TracePoint#disable returns without waiting for hooks still running on other threads. A hook block that changes shared state, like a Hash of counts, must synchronize on its own.
sampokuokkanen
force-pushed
the
tracepoint-thread-state
branch
from
November 18, 2026 03:40
3e93be7 to
198f5c4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A TracePoint's hook held a lock while its block ran, because the event data was stored on the TracePoint object. If a hook waits for another thread and that thread hits the same TracePoint, both threads hang. The debug gem does this: it stops inside a breakpoint's hook and waits for its session thread, which runs code the same TracePoint traces. So the debugger hangs as soon as a breakpoint is hit (ruby/debug#1120).
The event data now lives on the thread while the hook runs, as CRuby keeps it per execution context, and the hook takes no lock. As in CRuby, a TracePoint's attributes read the event of the hook running on the current thread, and
TracePoint#selfraises "access from outside" outside a hook.The hook of one TracePoint can now run on several threads at once, as
set_trace_funchooks already could, andTracePoint#disablereturns without waiting for hooks still running on other threads. A hook block that changes shared state must synchronize itself.