-
-
Notifications
You must be signed in to change notification settings - Fork 33.5k
gh-87512: Fix subprocess using timeout= on Windows blocking with a large input=
#142058
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
gh-87512: Fix subprocess using timeout= on Windows blocking with a large input=
#142058
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
87c0ac5 to
bdc28cc
Compare
Add test_communicate_timeout_large_input to verify that TimeoutExpired is raised promptly when communicate() is called with large input and a timeout, even when the subprocess doesn't consume stdin quickly. This test currently passes on POSIX (where select() is used) but is expected to fail on Windows where the stdin write blocks without checking the timeout. The test sends 128KB of input (larger than typical pipe buffers) to a subprocess that sleeps for 3 seconds before reading. With a 0.5s timeout, TimeoutExpired should be raised within a couple seconds, not after the subprocess finishes sleeping. After timeout, the test verifies that input continuation works by calling communicate() again and checking all data was received (testing the fix from pythongh-141473). Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
bdc28cc to
9b7fe29
Compare
subprocess using timeout= on Windows can block when a large input= is supplied
subprocess using timeout= on Windows can block when a large input= is suppliedsubprocess using timeout= on Windows blocking with a large input=
f05d0aa to
7d55f53
Compare
…arge stdin On Windows, Popen._communicate() previously wrote to stdin synchronously, which could block indefinitely if the subprocess didn't consume input quickly and the pipe buffer filled up. The timeout parameter was only checked when joining the reader threads, not during the stdin write. This change moves the stdin writing to a background thread (similar to how stdout/stderr are read in threads), allowing the timeout to be properly enforced. If timeout expires, TimeoutExpired is raised promptly and the writer thread continues in the background. Subsequent calls to communicate() will join the existing writer thread. Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
20d48a9 to
908fd43
Compare
|
🤖 New build scheduled with the buildbot fleet by @gpshead for commit 908fd43 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F142058%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again. |
|
Thanks @gpshead for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14. |
|
Thanks @gpshead for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13. |
… with a large `input=` (pythonGH-142058) On Windows, Popen._communicate() previously wrote to stdin synchronously, which could block indefinitely if the subprocess didn't consume input= quickly and the pipe buffer filled up. The timeout= parameter was only checked when joining the reader threads, not during the stdin write. This change moves the Windows stdin writing to a background thread (similar to how stdout/stderr are read in threads), allowing the timeout to be properly enforced. If timeout expires, TimeoutExpired is raised promptly and the writer thread continues in the background. Subsequent calls to communicate() will join the existing writer thread. Adds test_communicate_timeout_large_input to verify that TimeoutExpired is raised promptly when communicate() is called with large input and a timeout, even when the subprocess doesn't consume stdin quickly. This test already passed on POSIX (where select() is used) but failed on Windows where the stdin write blocks without checking the timeout. (cherry picked from commit 5b1862b) Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
|
GH-142068 is a backport of this pull request to the 3.14 branch. |
… with a large `input=` (pythonGH-142058) On Windows, Popen._communicate() previously wrote to stdin synchronously, which could block indefinitely if the subprocess didn't consume input= quickly and the pipe buffer filled up. The timeout= parameter was only checked when joining the reader threads, not during the stdin write. This change moves the Windows stdin writing to a background thread (similar to how stdout/stderr are read in threads), allowing the timeout to be properly enforced. If timeout expires, TimeoutExpired is raised promptly and the writer thread continues in the background. Subsequent calls to communicate() will join the existing writer thread. Adds test_communicate_timeout_large_input to verify that TimeoutExpired is raised promptly when communicate() is called with large input and a timeout, even when the subprocess doesn't consume stdin quickly. This test already passed on POSIX (where select() is used) but failed on Windows where the stdin write blocks without checking the timeout. (cherry picked from commit 5b1862b) Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
|
GH-142069 is a backport of this pull request to the 3.13 branch. |
…g with a large `input=` (GH-142058) (#142068) gh-87512: Fix `subprocess` using `timeout=` on Windows blocking with a large `input=` (GH-142058) On Windows, Popen._communicate() previously wrote to stdin synchronously, which could block indefinitely if the subprocess didn't consume input= quickly and the pipe buffer filled up. The timeout= parameter was only checked when joining the reader threads, not during the stdin write. This change moves the Windows stdin writing to a background thread (similar to how stdout/stderr are read in threads), allowing the timeout to be properly enforced. If timeout expires, TimeoutExpired is raised promptly and the writer thread continues in the background. Subsequent calls to communicate() will join the existing writer thread. Adds test_communicate_timeout_large_input to verify that TimeoutExpired is raised promptly when communicate() is called with large input and a timeout, even when the subprocess doesn't consume stdin quickly. This test already passed on POSIX (where select() is used) but failed on Windows where the stdin write blocks without checking the timeout. (cherry picked from commit 5b1862b) Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
…g with a large `input=` (GH-142058) (#142069) gh-87512: Fix `subprocess` using `timeout=` on Windows blocking with a large `input=` (GH-142058) On Windows, Popen._communicate() previously wrote to stdin synchronously, which could block indefinitely if the subprocess didn't consume input= quickly and the pipe buffer filled up. The timeout= parameter was only checked when joining the reader threads, not during the stdin write. This change moves the Windows stdin writing to a background thread (similar to how stdout/stderr are read in threads), allowing the timeout to be properly enforced. If timeout expires, TimeoutExpired is raised promptly and the writer thread continues in the background. Subsequent calls to communicate() will join the existing writer thread. Adds test_communicate_timeout_large_input to verify that TimeoutExpired is raised promptly when communicate() is called with large input and a timeout, even when the subprocess doesn't consume stdin quickly. This test already passed on POSIX (where select() is used) but failed on Windows where the stdin write blocks without checking the timeout. (cherry picked from commit 5b1862b) Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
On Windows,
Popen._communicate()previously wrote to stdin synchronously, which could block indefinitely if the subprocess didn't consumeinput=quickly and the pipe buffer filled up. Thetimeout=parameter was only checked when joining the reader threads, not during the stdin write.This change moves the Windows stdin writing to a background thread (similar to how stdout/stderr are read in threads), allowing the timeout to be properly enforced. If timeout expires, TimeoutExpired is raised promptly and the writer thread continues in the background. Subsequent calls to communicate() will join the existing writer thread.
Test driven development
I first added test_communicate_timeout_large_input to verify that TimeoutExpired is raised promptly when communicate() is called with large input and a timeout, even when the subprocess doesn't consume stdin quickly.
This test already passed on POSIX (where select() is used) but failed on Windows where the stdin write blocks without checking the timeout.