]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-112800: Ignore PermissionError on SubprocessTransport.close() in asyncio (#112803)
authorAllison Karlitskaya <allison.karlitskaya@redhat.com>
Sun, 24 Dec 2023 00:43:39 +0000 (01:43 +0100)
committerGitHub <noreply@github.com>
Sun, 24 Dec 2023 00:43:39 +0000 (16:43 -0800)
In case the spawned process is setuid, we may not be able to send
signals to it, in which case our .kill() call will raise
PermissionError.

Ignore that in order to avoid .close() raising an exception.  Hopefully
the process will exit as a result of receiving EOF on its stdin.

Lib/asyncio/base_subprocess.py
Misc/NEWS.d/next/Library/2023-12-06-16-01-33.gh-issue-112800.TNsGJ-.rst [new file with mode: 0644]

index 4c9b0dd5653c0c5478a70b6fa95c28015972b24e..6dbde2b696ad1fd2111c9db788d97991be0cc31b 100644 (file)
@@ -115,7 +115,8 @@ class BaseSubprocessTransport(transports.SubprocessTransport):
 
             try:
                 self._proc.kill()
-            except ProcessLookupError:
+            except (ProcessLookupError, PermissionError):
+                # the process may have already exited or may be running setuid
                 pass
 
             # Don't clear the _proc reference yet: _post_init() may still run
diff --git a/Misc/NEWS.d/next/Library/2023-12-06-16-01-33.gh-issue-112800.TNsGJ-.rst b/Misc/NEWS.d/next/Library/2023-12-06-16-01-33.gh-issue-112800.TNsGJ-.rst
new file mode 100644 (file)
index 0000000..e88eac1
--- /dev/null
@@ -0,0 +1,2 @@
+Fix :mod:`asyncio` ``SubprocessTransport.close()`` not to throw
+``PermissionError`` when used with setuid executables.