Bugfix: Signal Trace mode may send SIGURG to wrong thread#3039
Bugfix: Signal Trace mode may send SIGURG to wrong thread#3039chenBright merged 1 commit intoapache:masterfrom
Conversation
4abae57 to
8a48105
Compare
|
https://man7.org/linux/man-pages/man2/sigqueue.2.html
|
|
Perhaps we can use pthread_sigqueue which has better compatibility. https://man7.org/linux/man-pages/man3/pthread_sigqueue.3.html
|
It's okay. So I need to change the type of |
Yes. |
4ad9917 to
eecd82a
Compare
|
@chenBright Please review again. |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a signal handling bug in the Signal Trace mode where SIGURG was being sent to the wrong thread. The core issue was using process IDs (pid_t) instead of pthread IDs (pthread_t) for thread identification.
Key changes:
- Changed thread identification from
pid_ttopthread_tthroughout the codebase - Replaced
sigqueue()withpthread_sigqueue()for proper thread-specific signal delivery - Updated initialization values from
-1to0for pthread compatibility
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/bthread/task_tracer.h | Updated function signatures and member variables to use pthread_t |
| src/bthread/task_tracer.cpp | Implemented thread safety check and switched to pthread_sigqueue() |
| src/bthread/task_meta.h | Changed worker thread ID type from pid_t to pthread_t |
| src/bthread/task_group.h | Updated TaskGroup thread ID member and accessor method |
| src/bthread/task_group.cpp | Updated local variable type for consistency |
| src/bthread/task_control.cpp | Changed thread ID assignment from syscall(SYS_gettid) to pthread_self() |
| // Therefore, use async-signal-safe absl::DefaultStackUnwinder instead of libunwind. | ||
|
|
||
| if (worker_tid == pthread_self()) { | ||
| return Result::MakeErrorResult("Forbid to trace self=%d", worker_tid); |
There was a problem hiding this comment.
The format specifier %d is incorrect for pthread_t. pthread_t is an opaque type that may not be an integer on all platforms. Consider using %p to format it as a pointer or convert it appropriately for display.
| return Result::MakeErrorResult("Forbid to trace self=%d", worker_tid); | |
| return Result::MakeErrorResult("Forbid to trace self=%p", (void*)worker_tid); |
There was a problem hiding this comment.
On other platforms, pthread_t is not an integer, but a pointer.
| // Remove reference for SignalHandler. | ||
| signal_sync->RemoveRefManually(); | ||
| return Result::MakeErrorResult("Fail to sigqueue: %s, tid: %d", berror(), tid); | ||
| return Result::MakeErrorResult("Fail to pthread_sigqueue: %s, tid: %d", berror(), worker_tid); |
There was a problem hiding this comment.
The format specifier %d is incorrect for pthread_t. pthread_t is an opaque type that may not be an integer on all platforms. Consider using %p to format it as a pointer or convert it appropriately for display.
| return Result::MakeErrorResult("Fail to pthread_sigqueue: %s, tid: %d", berror(), worker_tid); | |
| return Result::MakeErrorResult("Fail to pthread_sigqueue: %s, tid: %p", berror(), (void*)worker_tid); |
There was a problem hiding this comment.
On other platforms, pthread_t is not an integer, but a pointer.
eecd82a to
ef2d16e
Compare
| // Therefore, use async-signal-safe absl::DefaultStackUnwinder instead of libunwind. | ||
|
|
||
| if (worker_tid == pthread_self()) { | ||
| return Result::MakeErrorResult("Forbid to trace self=%d", worker_tid); |
There was a problem hiding this comment.
On other platforms, pthread_t is not an integer, but a pointer.
| // Remove reference for SignalHandler. | ||
| signal_sync->RemoveRefManually(); | ||
| return Result::MakeErrorResult("Fail to sigqueue: %s, tid: %d", berror(), tid); | ||
| return Result::MakeErrorResult("Fail to pthread_sigqueue: %s, tid: %d", berror(), worker_tid); |
There was a problem hiding this comment.
On other platforms, pthread_t is not an integer, but a pointer.
e002e3a to
825625b
Compare
* Bugfix: Use `pthread_sigqueue` to send the signal to correct worker thread' * Change the type of `TaskGroup::_tid` to `pthread_t`
825625b to
5fe1a06
Compare
|
@chenBright ping |
rt_tgsigqueueinfoto send the signal to correct worker threadWhat problem does this PR solve?
Issue Number: fix #3038
Problem Summary:
What is changed and the side effects?
Changed:
Side effects:
Performance effects:
Breaking backward compatibility:
Check List: