Repository navigation
pty.spawn hangs on FreeBSD 9.3, 10.x, 12.1 #70416
Copy link
Copy link
Closed
Labels
3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.9 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = None
closed_at = <Date 2021-08-12.12:37:09.625>
created_at = <Date 2016-01-28.04:04:21.544>
labels = ['type-bug', 'library', '3.9', '3.10', '3.11']
title = 'pty.spawn hangs on FreeBSD 9.3, 10.x, 12.1'
updated_at = <Date 2021-08-13.11:21:14.284>
user = 'https://bugs.python.org/christorek'bugs.python.org fields:
activity = <Date 2021-08-13.11:21:14.284>
actor = 'miss-islington'
assignee = 'none'
closed = True
closed_date = <Date 2021-08-12.12:37:09.625>
closer = 'lukasz.langa'
components = ['Library (Lib)']
creation = <Date 2016-01-28.04:04:21.544>
creator = 'chris.torek'
dependencies = []
files = ['41738']
hgrepos = []
issue_num = 26228
keywords = ['patch']
message_count = 17.0
messages = ['259088', '259093', '284493', '284552', '284590', '292382', '306934', '336601', '336637', '336689', '336708', '375084', '399420', '399445', '399446', '399521', '399526']
nosy_count = 9.0
nosy_names = ['lukasz.langa', 'martin.panter', 'jbeck', 'RadicalZephyr', 'chris.torek', 'Cornelius Diekmann', 'miss-islington', 'jarryshaw', 'soumendra']
pr_nums = ['2932', '4167', '12049', '22962', '27732', '27754', '27758']
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue26228'
versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.9 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
christorek commentedon Jan 28, 2016
The pty.spawn() code assumes that when the process on the slave side of the pty quits, the master side starts raising OSError when read-from or written-to.
That used to be true in FBSD, but then someone fixed (?) it, and now the master side simply returns EOF when read-from. Furthermore, writes to the master simply disappear into the aether (this may be an OS bug, but even if the writes raised OSError, you would still have to type something in on stdin to get it copied over to get the error raised to get out of the loop).
The fix here makes an assumption that is true when using the built-in read calls: EOF on the master indicates that the slave is no longer reachable in any way and the whole thing should finish up immediately. It might perhaps need a bit of documentation should someone want to substitute in their own read function (see enhancement request in bpo-22865).
I also fixed (sort of) bpo-17824, but only barely minimally, and put in a comment that it should really use the same mechanism as subprocess (but I think that should be a separate patch).
vadmium commentedon Jan 28, 2016
I agree with all the changes you made. I made one review comment.
It would be nice to add a test case to expose the problem. Correct me if I am wrong, but it doesn’t look like pty.spawn() is tested at all.
FWIW on Linux, reading from the master end seems to raise EIO if the slave has been closed. And writing to the master when the slave is closed seems to fill up a buffer and eventually blocks.
Ideally I think the best solution for handing exec() failure (bpo-17824) would be to eliminate fork-exec with posix_spawn(); see bpo-20104. But as you say, that’s a separate problem.
diekmann commentedon Jan 2, 2017
I just tested pty.spawn() on OS X 10.6.8 and FreeBSD 11 and it also hangs. It works on Linux.
Your patch solves the problem. I proposed a test suite for pty.spawn() in bpo-29070. The test suite currently only exposes the problem, as suggested by Martin.
vstinner commentedon Jan 3, 2017
Is it a behaviour change in a new version of Python? Or a change in FreeBSD? I don't understand.
vadmium commentedon Jan 3, 2017
Behaviour change in Free BSD as I understand. Nothing changed in Python, but perhaps older versions of Free BSD behaved like Linux and raised EIO (or another errno; it is not clear).
jbeck commentedon Apr 26, 2017
Solaris has this problem also, and Chris' patch fixes it for us.
vadmium commentedon Nov 25, 2017
If it helps, here is a basic test case I wrote for “pty.spawn”. I hope that it exposes the problem on Free BSD, but I have only tested it on Linux.
JarryShaw commentedon Feb 26, 2019
Chris' patch works on macOS 10.14 (Mojave); but after it terminates, tty attributes are not restored (new-lines are missing). btw, I've implemented a workaround library with solution through either
pscommand orpsutilpackage, seeptyngon PyPI.RadicalZephyr commentedon Feb 26, 2019
I took a shot at fixing this in a smaller more targeted patch. I think this should still solve the major issue of pty.spawn hanging on platforms that don't raise an error. In addition, pty.spawn should now _ALWAYS_ return the terminal to the previous settings.
vstinner commentedon Feb 26, 2019
Please have a look at this pty.spawn() documentation change:
#11980
RadicalZephyr commentedon Feb 26, 2019
I'm aware of it. I actually wrote that patch as well. :D
8vasu commentedon Aug 9, 2020
Hi! Can anyone please take a look at
https://bugs.python.org/issue41494 [ https://github.com//pull/21752 ]?
I think these are related. I wrote a new function called wspawn, which is like spawn+the following differences.
[-]pty.spawn hangs on FreeBSD 9.3, 10.x[/-][+]pty.spawn hangs on FreeBSD 9.3, 10.x, 12.1[/+]ambv commentedon Aug 11, 2021
New changeset 81ab8db by Zephyr Shannon in branch 'main':
bpo-26228: Fix pty EOF handling (GH-12049)
81ab8db
ambv commentedon Aug 12, 2021
New changeset 5d44443 by Miss Islington (bot) in branch '3.10':
bpo-26228: Fix pty EOF handling (GH-12049) (GH-27732)
5d44443
ambv commentedon Aug 12, 2021
This is now merged. Thanks for all input, everyone! ✨ 🍰 ✨
ambv commentedon Aug 13, 2021
New changeset dd8eb30 by Łukasz Langa in branch 'main':
bpo-26228: [doc] Adapt PTY documentation updates from #48417 (GH-27754)
dd8eb30
miss-islington commentedon Aug 13, 2021
New changeset d412848 by Miss Islington (bot) in branch '3.10':
bpo-26228: [doc] Adapt PTY documentation updates from #48417 (GH-27754)
d412848