-
Notifications
You must be signed in to change notification settings - Fork 7
Bound the AutoSetup wait, and stop the task holding it from outliving the run #208
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
Open
shellygr
wants to merge
4
commits into
master
Choose a base branch
from
shelly/autosetup-reap-timeout
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
63af10d
Bound the wait for the AutoSetup subprocess
shellygr f9a9948
Scope the formalization task to the extraction it runs beside
shellygr 51b1ea9
Say how the AutoSetup wait ended, and what the loop still holds at sh…
shellygr 59e1ab0
Merge master into the AutoSetup reap branch
shellygr 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| """Tests for the bounded reap of the AutoSetup subprocess (``composer/spec/source/autosetup.py``). | ||
|
|
||
| The wait for the child sits in a ``finally``, which is also the path a cancelled run takes on its | ||
| way out. Whatever the child is doing, that wait has to end. | ||
| """ | ||
|
|
||
| import asyncio | ||
| import sys | ||
|
|
||
| import pytest | ||
|
|
||
| from composer.spec.source import autosetup | ||
|
|
||
| pytestmark = pytest.mark.asyncio | ||
|
|
||
|
|
||
| async def _spawn(code: str) -> asyncio.subprocess.Process: | ||
| return await asyncio.create_subprocess_exec( | ||
| sys.executable, "-c", code, | ||
| stdout=asyncio.subprocess.DEVNULL, | ||
| stderr=asyncio.subprocess.DEVNULL, | ||
| stdin=asyncio.subprocess.DEVNULL, | ||
| ) | ||
|
|
||
|
|
||
| async def test_a_child_that_exits_reports_its_status(): | ||
| proc = await _spawn("raise SystemExit(3)") | ||
| assert await autosetup._reap(proc) == 3 | ||
|
|
||
|
|
||
| async def test_a_child_that_will_not_exit_is_killed(monkeypatch): | ||
| monkeypatch.setattr(autosetup, "_REAP_TIMEOUT_S", 0.2) | ||
| # Ignores SIGTERM, so only the kill ends it. | ||
| proc = await _spawn( | ||
| "import signal, time; signal.signal(signal.SIGTERM, signal.SIG_IGN); time.sleep(300)" | ||
| ) | ||
| returncode = await asyncio.wait_for(autosetup._reap(proc), timeout=10) | ||
| assert returncode is not None and returncode < 0 |
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.
I'm confused, do we know why this hung? how did
proc.kill(); proc.wait()not work??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.
I am also confused how it happened, but either the kill in the exception didn't kill the process on a timely manner, or
gatherreturned without the process actually ending. The question is whether we think that this fix is hiding a more serious issue.Claude's commentary:
▎ We don't. The run sat in that wait until the job's hard time cap killed
▎ the process, so there was nothing left to inspect.
▎
▎ On the kill: it only runs in the except BaseException branch. If the gather returns
▎ normally with the child still alive, nothing kills it, and the old await proc.wait()
▎ in the finally just blocks. And where we do kill, the wait after it was that same
▎ unbounded wait, so a child that doesn't die on SIGKILL parks the run the same way. The
▎ bound is what ends it either way.
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.
Claude answers: We do now, from the container logs. One of the two runs ends with the CancelledError coming out of
_drain, then the debug line in thefinally. Soasyncio.run's teardown cancelled the drain,proc.kill()did run, and the run was last seen going into the unboundedproc.wait().The kill only exists in the except branch, and the wait after it is that same unbounded wait, so nothing there was a bound on anything. Whether the wait itself is what held for 22h I can't tell from that log, because nothing logged when it returned. The other run froze at the same point in teardown with its autosetup already exited 0, so this isn't the whole incident.
I've pushed the rest: the task holding the subprocess is now cancelled with the extraction it runs beside instead of being left for teardown, the reap logs how it ended, and there's a test for the path that actually happened.