Skip to content

Conversation

tyroguru
Copy link
Collaborator

Summary

Our initial thread seize code is very racy and it's super easy to end up with threads being ignored or hung for long periods waiting for stop states to be reaped. This change aims to handle the case where a thread that has been seized executes a sequence such that a new thread is created (e.g., a clone(2) syscall and the newborn thread shows up in the /proc namespace so the directory_iterator picks it up. This new thread will be traced by us already as the tracing sate is inherited from its parent thread so we can't seize it. It will however be in a signal-stop state so that should be reaped and the thread continued.

Test plan

make 'test' returns the same failures as before the change. However, it is unlikely to show any change as this code is handling an EPERM return from ptrace(2). Test in prod really. I have engineered highly controlled test cases to work through the failure scenarios and at a minimum I don't think we are any more exposed to failure with this code than without.

@codecov-commenter
Copy link

codecov-commenter commented Jul 22, 2023

Codecov Report

❌ Patch coverage is 10.52632% with 34 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.81%. Comparing base (b834c92) to head (fc17579).
⚠️ Report is 261 commits behind head on main.

Files with missing lines Patch % Lines
oi/OIDebugger.cpp 10.52% 32 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #255      +/-   ##
==========================================
- Coverage   66.99%   66.81%   -0.19%     
==========================================
  Files          99       99              
  Lines       10321    10348      +27     
  Branches     1709     1718       +9     
==========================================
- Hits         6915     6914       -1     
- Misses       2523     2549      +26     
- Partials      883      885       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tyroguru tyroguru requested review from JakeHillion and ttreyer July 22, 2023 10:15
@tyroguru tyroguru marked this pull request as draft July 24, 2023 09:43
Copy link
Contributor

@JakeHillion JakeHillion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷‍♂️

if (ptrace(PTRACE_SINGLESTEP, pid, 0, 0) == -1) {
LOG(ERROR) << "Error in singlestep!";
LOG(ERROR) << "singleStepInst: ptrace single error: " << strerror(errno);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this can be replaced with PLOG(ERROR) << "singleStepInst: ptrace single error: "; similarly with the other cases that append strerror.

@@ -64,7 +64,7 @@ class OIDebugger {
OIDebugger::processTrapRet processTrap(pid_t, bool = true, bool = true);
bool contTargetThread(bool detach = true) const;
bool isGlobalDataProbeEnabled(void) const;
static uint64_t singlestepInst(pid_t, struct user_regs_struct&);
static uint64_t singleStepInst(pid_t, struct user_regs_struct&);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should this return uintptr_t? it's casted to that at one of the call sites and seems to make more sense. obviously they're the same type though.

@@ -968,7 +980,7 @@ OIDebugger::processTrapRet OIDebugger::processTrap(pid_t pid,
siginfo_t info;

auto stopsig = WSTOPSIG(status);
VLOG(4) << "Stop sig: " << std::dec << stopsig;
VLOG(3) << "Stop sig: " << std::dec << stopsig;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if this was for debugging, but shouldn't this remain a 4?

@facebook-github-bot
Copy link

Hi @tyroguru!

Thank you for your pull request.

We require contributors to sign our Contributor License Agreement, and yours needs attention.

You currently have a record in our system, but the CLA is no longer valid, and will need to be resubmitted.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants