Skip to content
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

CI: Reliability, eliminate a race condition and some resource leaks #1119

Merged
merged 7 commits into from
Sep 10, 2024

Conversation

moreati
Copy link
Member

@moreati moreati commented Sep 10, 2024

This improves the situation wrt #1058. It should eliminate the most painful intermittent failure

AssertionError: Docker container 'mitogen-test-...' contained extra running processes after test completed

fixes #694

This should terminate any child processes and connections.
Python 3.x emits `ResourceWarning`s if certains resources aren't correctly
closed. Due to the way Mitogen has been terminating child processes this has
been occurring.

```
test_dev_tty_open_succeeds
(create_child_test.TtyCreateChildTest.test_dev_tty_open_succeeds) ...
/opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/subprocess.py:1127:
ResourceWarning: subprocess 3313 is still running
  _warn("subprocess %s is still running" % self.pid,
ResourceWarning: Enable tracemalloc to get the object allocation traceback
ok
```

During garbage collection subprocess.Popen() objects emit
ResourceWarning("subprocess 123 is still running")
if proc.returncode hasn't been set. Typically calling proc.wait() does so,
once the sub-process has exited. Calling os.waitpid(proc.pid, 0) also waits
for the sub-process to exit, but it doesn't update proc.returncode, so the
ResourceWarning is still emitted.

This change exposes `subprocess.Popen` methods on
`mitogen.parent.PopenProcess`, so that the returncode can be set.

See https://gist.github.com/moreati/b8d157ff82cb15234bece4033accc5e5
It's not noisy, and it has been hiding an error I wasn't aware of.
I'm about 75% sure the check is an unavoidable race condition, see
mitogen-hq#694 (comment). If
it occurs again, then reopen the issue.

Fixes mitogen-hq#694
@moreati moreati force-pushed the ci-resourcewarnings branch from af97887 to d032c59 Compare September 10, 2024 15:45
@moreati moreati merged commit b8b1558 into mitogen-hq:master Sep 10, 2024
44 checks passed
@moreati moreati deleted the ci-resourcewarnings branch September 10, 2024 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AssertionError: Docker container '...' contained extra running processes after test completed
1 participant