-
Couldn't load subscription status.
- Fork 15k
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
64947d4
Avoid stalls when MainLoop::Interrupt fails to wake up the
jimingham c5990ba
Formatting
jimingham 37b37c2
Address review comments.
jimingham cc83cd7
Review suggestion.
jimingham f600f1d
Merge branch 'main' into avoid-mainloop-stall
jimingham 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
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
51 changes: 51 additions & 0 deletions
51
lldb/test/API/driver/stdio_closed/TestDriverWithClosedSTDIO.py
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 |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| """ | ||
| 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 TestDriverWithClosedSTDIO(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", | ||
| "-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.") |
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
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.
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.