New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Name the async_cb_thread for easier debugging #883
Conversation
I found this useful while reviewing DataDog/dd-trace-rb#1371 -- we were searching for specs that leaked threads, and saw a "mysterious" thread with no stack that we couldn't exactly point out what created it or why it existed. By setting a name on the callback thread, it becomes immediately obvious when looking at `Thread.list` what this thread is and where it comes from. (Thread naming has been around [since Ruby 2.3](https://github.com/ruby/ruby/blob/v2_3_0/NEWS) which means we can do it safely for every supported version)
I'll submit this separately.
To name the thread is a great idea! Two thoughts:
|
I'll take a look at it separately as well.
Thanks for the feedback!
Yeap, already skipped both. It's weird that CI for JRuby seemed to pass even without my change, because locally I did see that it didn't work on JRuby.
Sounds good! I'll look into it -- I'm guessing it needs a bit of wrapping, because the |
Unfortunately github actions doesn't support allow_failure so far, so that we use
I think it's OK to set the thread name from the thread calling |
Similar to what was done for the dispatcher thread.
Done! I ended up using "Callback Runner" since it was a bit weird to have a "FFI::Function Callback" and a "FFI::Function Callback Dispatcher", but let me know if you still prefer your original suggestion :) |
Hmmm I guess I have some debugging to do on windows. I'm guessing it may be due to the racy manner in which we set the name in one thread and then access it in the other. |
spec/ffi/async_callback_spec.rb
Outdated
|
||
thread_name = nil | ||
|
||
LibTest.testAsyncCallback(proc { thread_name = Thread.current.name }, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be race-free to store Thread.current
here and call Thread#name
below. The name is readable even if the thread has terminated.
This was probably failing due to thread naming being a racy operation; by keeping a reference to the thread and checking it after the call finishes, this will hopefully be enough for the name to become available.
https://github.com/ffi/ffi/blob/master/spec/ffi/fixtures/FunctionTest.c#L128 I can try to name the thread all day long! The "async" callback is not async on windows xD Took me a bit to debug this ahahaha :) |
Thanks for picking up the last bit @larskanis! I admit I was not having much sucess poking at the win32 bits and fighting with 🙇 thanks for the help! |
No problem. Thank you for contributing this! |
I found this useful while reviewing DataDog/dd-trace-rb#1371 -- we were searching for specs that leaked threads, and saw a "mysterious" thread with no stack that we couldn't exactly point out what created it or why it existed.
By setting a name on the callback thread, it becomes immediately obvious when looking at
Thread.list
what this thread is and where it comes from.(Thread naming has been around since Ruby 2.3 which means we can do it safely for every supported version)