Author Cornelius Diekmann
Recipients Cornelius Diekmann, martin.panter
Date 2016-12-23.14:17:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1482502637.76.0.304881442895.issue29054@psf.upfronthosting.co.za>
In-reply-to
Content
My OS: Debian GNU/Linux 8.6 (jessie)
Python 3.4.2
pty.py from Python-3.5.2/Lib (pty.py is just a tiny, portable python file which did not see many changes)


Bug Report

Steps to Reproduce:

I wrote a very simple python remote shell:

#!/usr/bin/env python3
import pty
pty.spawn('/bin/sh')


It can be run in a terminal (call it TermA) with `nc -e ./myfancypythonremoteshell.py -l -p 6699`
In a different terminal (call it TermB), I connect to my fancy remote shell with `nc 127.0.0.1 6699`.
The shell works fine. In TermB, I quit by pressing ctrl+c.

Observed Behavior: In TermA, the nc process, the python process, and the spawned /bin/sh still exist. They still occupy TermA.

Expected Behavior: The client in TermB has disconnected, /bin/sh in TermA can no longer read anything from stdin and it should close down. Ultimately, in TermA, nc should have exited successfully.

Fix: End the _copy loop in pty.py once EOF in STDIN is reached. Everything shuts itself down automatically. I included a small patch to demonstrate this behavior.

This patch is not meant to go straight into production. I have not verified if this behavior somehow breaks other use cases. This bug report is meant to document exactly one specific use case and supply exactly one line of code change for it.

This issue is related to issue26228. Actually, it is complementary. issue26228 wants to return if master_fd is EOF, this issue wants to return if stdin is EOF. Both behaviors together looks good to me. By the way, I hacked a hacky `assert False` into my patch as a placeholder for issue26228's proper handling of exec failures at that part of the code.

I suggest to combine the patches of this issue and issue26228.
History
Date User Action Args
2016-12-23 14:17:17Cornelius Diekmannsetrecipients: + Cornelius Diekmann, martin.panter
2016-12-23 14:17:17Cornelius Diekmannsetmessageid: <1482502637.76.0.304881442895.issue29054@psf.upfronthosting.co.za>
2016-12-23 14:17:17Cornelius Diekmannlinkissue29054 messages
2016-12-23 14:17:16Cornelius Diekmanncreate