https://github.com/jasonmolenda created 
https://github.com/llvm/llvm-project/pull/99962

After lldb has ptrace()'ed the process, it sleeps for 0.25 seconds before 
trying to pause the process.  We see logging that in some rare cases, this 
sleep is interrupted and the pause fails, the attach fails.  usleep(3) says 
that the only errno it will return is EINTR if interrupted, so retry on that 
case.  I capped it at four retries so the process can't hang infinitely if it's 
being spammed with asynchronous signals.

I don't know what environment setup results in this behavior, it's only rarely 
seen by end users and we see evidence, after the fact of it, in logging.

rdar://131602093

>From 01255f7c906c9b5995b0f33c420c7c7eb707bddf Mon Sep 17 00:00:00 2001
From: Jason Molenda <jmole...@apple.com>
Date: Mon, 22 Jul 2024 14:55:04 -0700
Subject: [PATCH] [lldb][debugserver] Retry sleep(0.25s) when interrupted

After lldb has ptrace()'ed the process, it sleeps for 0.25 seconds
before trying to pause the process.  We see logging that in some
rare cases, this sleep is interrupted and the pause fails.  usleep(3)
says that the only errno it will return is EINTR if interrupted,
so retry on that case.  I capped it at four retries so the process
can't hang infinitely if it's being spammed with asynchronous
signals.

I don't know what environment setup results in this behavior,
it's only rarely seen by end users and we see evidence, after
the factof it, in logging.

rdar://131602093
---
 lldb/tools/debugserver/source/MacOSX/MachProcess.mm | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/lldb/tools/debugserver/source/MacOSX/MachProcess.mm 
b/lldb/tools/debugserver/source/MacOSX/MachProcess.mm
index cbe3c5459e91f..89c031fdc75d6 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachProcess.mm
+++ b/lldb/tools/debugserver/source/MacOSX/MachProcess.mm
@@ -2846,9 +2846,12 @@ static uint64_t bits(uint64_t value, uint32_t msbit, 
uint32_t lsbit) {
     if (err.Success()) {
       m_flags |= eMachProcessFlagsAttached;
       // Sleep a bit to let the exception get received and set our process
-      // status
-      // to stopped.
-      ::usleep(250000);
+      // status to stopped.
+      int max_retry = 4;
+      do {
+        errno = 0;
+        usleep(250000); // If our 0.25 second sleep is interrupted, redo
+      } while (errno == EINTR && --max_retry > 0);
       DNBLog("[LaunchAttach] (%d) Done napping after ptrace(PT_ATTACHEXC)'ing",
              getpid());
       DNBLogThreadedIf(LOG_PROCESS, "successfully attached to pid %d", pid);

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to