From owner-freebsd-bugs@freebsd.org Wed Nov 25 17:34:27 2015 Return-Path: Delivered-To: freebsd-bugs@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 24A1AA36B35 for ; Wed, 25 Nov 2015 17:34:27 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id EAD47145E for ; Wed, 25 Nov 2015 17:34:26 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from bugs.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id tAPHYQCo090540 for ; Wed, 25 Nov 2015 17:34:26 GMT (envelope-from bugzilla-noreply@freebsd.org) From: bugzilla-noreply@freebsd.org To: freebsd-bugs@FreeBSD.org Subject: [Bug 204812] pty read blocks after select, if ^S is written in between Date: Wed, 25 Nov 2015 17:34:27 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: 10.2-RELEASE X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: cgull@glup.org X-Bugzilla-Status: New X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: freebsd-bugs@FreeBSD.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Nov 2015 17:34:27 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=204812 Bug ID: 204812 Summary: pty read blocks after select, if ^S is written in between Product: Base System Version: 10.2-RELEASE Hardware: amd64 OS: Any Status: New Severity: Affects Only Me Priority: --- Component: kern Assignee: freebsd-bugs@FreeBSD.org Reporter: cgull@glup.org The pts driver has an issue with breaking the promise made by select() that a read will not block, if there is a write of ^S to the pty between the select() and the read(). The reproduction for this is very simple: script /dev/null yes Type ^S. Type ^Q. Nothing happens, because script is hung on a blocking read. The read will never complete, because script is hung and your ^Q will never be delivered. I originally discovered this while working on mosh (net/mosh), but script blocks in the same way. The sequence of events that causes this: * The pty slave has software flow control enabled. * select() returns read status for the pty master fd. * Something write()s ^S to the pty master. * A read() is started on the pty master, with the expectation that it will not block. But it does block, and since the tty is stopped, it will never unblock without outside intervention. I hesitate to call this a bug, because the state of the pty *is* changed by that write, and the fix for this issue is not clear. But it violates POLA, other kernels (Linux, OpenBSD) do not behave this way, and the consequences are serious. I see this issue on FreeBSD 10.2, 9.1, and 7.2. An old 4.10 box doesn't have this issue. I originally discovered this bug while working on Mosh. It's not a new bug there. I've now implemented pty packet mode, and the problem exists there too, even though packet mode should always be able to avoid breaking this promise. See https://github.com/mobile-shell/mosh/issues/692 https://github.com/cgull/mosh/tree/pty-packet I don't understand why nobody has run into this issue before though, either on the FreeBSD or on the Mosh side. (Mosh has this problem on FreeBSD and OS X.) -- You are receiving this mail because: You are the assignee for the bug.