-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Bugfix: Signal Trace mode may send SIGURG to wrong thread #3039
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,17 +18,18 @@ | |||||||||||
| #ifdef BRPC_BTHREAD_TRACER | ||||||||||||
|
|
||||||||||||
| #include "bthread/task_tracer.h" | ||||||||||||
| #include <unistd.h> | ||||||||||||
| #include <poll.h> | ||||||||||||
| #include <gflags/gflags.h> | ||||||||||||
| #include <absl/debugging/stacktrace.h> | ||||||||||||
| #include <absl/debugging/symbolize.h> | ||||||||||||
| #include "butil/debug/stack_trace.h" | ||||||||||||
| #include "bthread/processor.h" | ||||||||||||
| #include "bthread/task_group.h" | ||||||||||||
| #include "butil/fd_utility.h" | ||||||||||||
| #include "butil/memory/scope_guard.h" | ||||||||||||
| #include "butil/reloadable_flags.h" | ||||||||||||
| #include "butil/fd_utility.h" | ||||||||||||
| #include "bthread/task_group.h" | ||||||||||||
| #include "bthread/processor.h" | ||||||||||||
| #include <absl/debugging/stacktrace.h> | ||||||||||||
| #include <absl/debugging/symbolize.h> | ||||||||||||
| #include <csignal> | ||||||||||||
| #include <gflags/gflags.h> | ||||||||||||
| #include <poll.h> | ||||||||||||
| #include <pthread.h> | ||||||||||||
| #include <unistd.h> | ||||||||||||
|
|
||||||||||||
| namespace bthread { | ||||||||||||
|
|
||||||||||||
|
|
@@ -151,7 +152,7 @@ void TaskTracer::set_status(TaskStatus s, TaskMeta* m) { | |||||||||||
| m->status = s; | ||||||||||||
| } | ||||||||||||
| if (TASK_STATUS_CREATED == s) { | ||||||||||||
| m->worker_tid = -1; | ||||||||||||
| m->worker_tid = pthread_t{}; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
|
|
@@ -161,7 +162,7 @@ void TaskTracer::set_status(TaskStatus s, TaskMeta* m) { | |||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| void TaskTracer::set_running_status(pid_t worker_tid, TaskMeta* m) { | ||||||||||||
| void TaskTracer::set_running_status(pthread_t worker_tid, TaskMeta* m) { | ||||||||||||
| BAIDU_SCOPED_LOCK(m->version_lock); | ||||||||||||
| m->worker_tid = worker_tid; | ||||||||||||
| m->status = TASK_STATUS_RUNNING; | ||||||||||||
|
|
@@ -230,7 +231,7 @@ TaskTracer::Result TaskTracer::TraceImpl(bthread_t tid) { | |||||||||||
|
|
||||||||||||
| BAIDU_SCOPED_LOCK(_mutex); | ||||||||||||
| TaskStatus status; | ||||||||||||
| pid_t worker_tid; | ||||||||||||
| pthread_t worker_tid; | ||||||||||||
| const uint32_t given_version = get_version(tid); | ||||||||||||
| { | ||||||||||||
| BAIDU_SCOPED_LOCK(m->version_lock); | ||||||||||||
|
|
@@ -368,7 +369,7 @@ void TaskTracer::SignalHandler(int, siginfo_t* info, void* context) { | |||||||||||
| butil::ignore_result(write(signal_sync->pipe_fds[1], "1", 1)); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| TaskTracer::Result TaskTracer::SignalTrace(pid_t tid) { | ||||||||||||
| TaskTracer::Result TaskTracer::SignalTrace(pthread_t worker_tid) { | ||||||||||||
| // CAUTION: | ||||||||||||
| // https://github.com/gperftools/gperftools/wiki/gperftools'-stacktrace-capturing-methods-and-their-issues#libunwind | ||||||||||||
| // Generally, libunwind promises async-signal-safety for capturing backtraces. | ||||||||||||
|
|
@@ -403,6 +404,10 @@ TaskTracer::Result TaskTracer::SignalTrace(pid_t tid) { | |||||||||||
| // | ||||||||||||
| // Therefore, use async-signal-safe absl::DefaultStackUnwinder instead of libunwind. | ||||||||||||
|
|
||||||||||||
| if (pthread_equal(worker_tid, pthread_self())) { | ||||||||||||
| return Result::MakeErrorResult("Forbid to trace self"); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // Remove unused SignalSyncs. | ||||||||||||
| auto iter = std::remove_if( | ||||||||||||
| _inuse_signal_syncs.begin(), _inuse_signal_syncs.end(), | ||||||||||||
|
|
@@ -424,11 +429,11 @@ TaskTracer::Result TaskTracer::SignalTrace(pid_t tid) { | |||||||||||
| sigval value{}; | ||||||||||||
| value.sival_ptr = signal_sync.get(); | ||||||||||||
| size_t sigqueue_try = 0; | ||||||||||||
|
||||||||||||
| size_t sigqueue_try = 0; | |
| size_t sigqueue_try = 0; | |
| // Use rt_tgsigqueueinfo instead of sigqueue to send a signal to a specific thread | |
| // (worker_tid) within the process. The standard sigqueue function does not support | |
| // targeting individual threads, which is essential for this implementation. |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.