-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Avoid stalls when MainLoop::Interrupt fails to wake up the MainLoop #164905
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
Changes from 2 commits
64947d4
c5990ba
37b37c2
cc83cd7
f600f1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -387,10 +387,13 @@ void MainLoopPosix::ProcessSignal(int signo) { | |
| } | ||
| } | ||
|
|
||
| void MainLoopPosix::Interrupt() { | ||
| bool MainLoopPosix::Interrupt() { | ||
| if (m_interrupting.exchange(true)) | ||
| return; | ||
| return true; | ||
|
|
||
| char c = '.'; | ||
| cantFail(m_interrupt_pipe.Write(&c, 1)); | ||
| llvm::Expected<size_t> result = m_interrupt_pipe.Write(&c, 1); | ||
| if (result && *result != 0) | ||
| return true; | ||
| return false; | ||
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -272,4 +272,7 @@ Status MainLoopWindows::Run() { | |
| return Status(); | ||
| } | ||
|
|
||
| void MainLoopWindows::Interrupt() { WSASetEvent(m_interrupt_event); } | ||
| bool MainLoopWindows::Interrupt() { | ||
| WSASetEvent(m_interrupt_event); | ||
|
||
| return true; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| """ | ||
| Test that if you exec lldb with the stdio file handles | ||
| closed, it is able to exit without hanging. | ||
| """ | ||
|
|
||
|
|
||
| import lldb | ||
| import os | ||
| import sys | ||
| import socket | ||
| import fcntl | ||
|
|
||
| import lldbsuite.test.lldbutil as lldbutil | ||
| from lldbsuite.test.lldbtest import * | ||
|
|
||
|
|
||
| class RenameThisSampleTestTestCase(TestBase): | ||
|
||
| # If your test case doesn't stress debug info, then | ||
| # set this to true. That way it won't be run once for | ||
| # each debug info format. | ||
| NO_DEBUG_INFO_TESTCASE = True | ||
|
|
||
| def test_run_lldb_and_wait(self): | ||
| """This test forks, closes the stdio channels and exec's lldb. | ||
| Then it waits for it to exit and asserts it did that successfully""" | ||
| pid = os.fork() | ||
| if pid == 0: | ||
| fcntl.fcntl(sys.stdin, fcntl.F_SETFD, fcntl.FD_CLOEXEC) | ||
| fcntl.fcntl(sys.stdout, fcntl.F_SETFD, fcntl.FD_CLOEXEC) | ||
| fcntl.fcntl(sys.stderr, fcntl.F_SETFD, fcntl.FD_CLOEXEC) | ||
| lldb = lldbtest_config.lldbExec | ||
| print(f"About to run: {lldb}") | ||
| os.execlp( | ||
| lldb, | ||
| lldb, | ||
| "-x", | ||
| "-b", | ||
|
||
| "-o", | ||
| "script print(lldb.debugger.GetNumTargets())", | ||
| "--batch", | ||
| ) | ||
| else: | ||
| if pid == -1: | ||
| print("Couldn't fork a process.") | ||
| return | ||
| ret_pid, status = os.waitpid(pid, 0) | ||
| # We're really just checking that lldb doesn't stall. | ||
| # At the time this test was written, if you close stdin | ||
| # in an asserts build, lldb aborts. So handle both | ||
| # of those cases. The failure will just be that the | ||
| # waitpid doesn't return, and the test times out. | ||
| self.assertFalse(os.WIFSTOPPED(status), "We either exited or crashed.") | ||
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.
Can we get a errno
EAGAINorEINTRduring this write? Looking at the::writellvm-project/lldb/source/Host/posix/PipePosix.cpp
Line 339 in 09cf301
Maybe we can wrap the
writecall inllvm-project/llvm/include/llvm/Support/Errno.h
Line 33 in 6dd78f6
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.
The error in the particular case I was addressing was that the interrupt pipe that we were trying to write to got closed out from under us. The error was "bad file handle". Since Write wasn't actually at fault here, I wasn't setting out to make the Write more robust. In this patch, I'm just trying to make sure the error gets reported so we don't stall waiting to join a thread that's never going to exit.
Making Write more robust in against interrupts would be a fine thing to do but is outside the scope of this patch.