From konsole-devel Wed Mar 08 02:04:22 2017 From: Kurt Hindenburg Date: Wed, 08 Mar 2017 02:04:22 +0000 To: konsole-devel Subject: Re: Review Request 129984: Prevent misdetection of EOF on Linux Message-Id: <20170308020422.13092.89535 () mimi ! kde ! org> X-MARC-Message: https://marc.info/?l=konsole-devel&m=148893866825892 --===============4823119506918845884== MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit ----------------------------------------------------------- This is an automatically generated e-mail. To reply, visit: https://git.reviewboard.kde.org/r/129984/#review102758 ----------------------------------------------------------- Since this changes kpty, it needs to get reviewed on https://phabricator.kde.org/ - can you please open a request there? - Kurt Hindenburg On March 4, 2017, 10:56 p.m., Peter Wu wrote: > > ----------------------------------------------------------- > This is an automatically generated e-mail. To reply, visit: > https://git.reviewboard.kde.org/r/129984/ > ----------------------------------------------------------- > > (Updated March 4, 2017, 10:56 p.m.) > > > Review request for Konsole and Kurt Hindenburg. > > > Bugs: 372991 > https://bugs.kde.org/show_bug.cgi?id=372991 > > > Repository: kpty > > > Description > ------- > > On Linux, even if slave activity is detected on a master fd, FIONREAD > can still return zero available bytes in the buffer. Previously this > would prevent further signals from being emitted even if new IO arrived > (since the readNotifier is disabled) which in its turn prevented the > Konsole output from being updated. > > A race condition in the kernel is suspected, the first known broken > kernel is v4.1.10-89-g5eb491ba5d06. > > BUG: 372991 > > > Diffs > ----- > > src/kptydevice.cpp 22233a505d32d988795839cb592098c38f7fab33 > > Diff: https://git.reviewboard.kde.org/r/129984/diff/ > > > Testing > ------- > > Tested in conjunction with konsole v16.12.1-60-g151215a9 with this debug patch applied: > ``` > diff --git a/src/kptydevice.cpp b/src/kptydevice.cpp > index 92b443b..4dfcd02 100644 > --- a/src/kptydevice.cpp > +++ b/src/kptydevice.cpp > @@ -273,6 +273,7 @@ struct KPtyDevicePrivate : public KPtyPrivate { > KRingBuffer writeBuffer; > }; > > +#include > bool KPtyDevicePrivate::_k_canRead() > { > Q_Q(KPtyDevice); > @@ -310,6 +311,9 @@ bool KPtyDevicePrivate::_k_canRead() > // select() will trigger again anyway if an EOF condition was found, and > // only then we will accept it. > if (!available && !maybeEof) { > + FILE *fp = fopen("/tmp/EOF", "a"); > + fprintf(fp, "Maybe EOF!?\n"); > + fclose(fp); > maybeEof = true; > return true; > } else if (available) { > > ``` > > Indeed, the /tmp/EOF file is being written and the Konsole output no longer "hangs". > > Closing a tab (via EOF in bash or closing the tab) somehow does not trigger this debug print, perhaps the watcher is disabled elsewhere. (This is an observation and not a problem.) > > > Thanks, > > Peter Wu > > --===============4823119506918845884== MIME-Version: 1.0 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: 7bit
This is an automatically generated e-mail. To reply, visit: https://git.reviewboard.kde.org/r/129984/

Since this changes kpty, it needs to get reviewed on https://phabricator.kde.org/ - can you please open a request there?


- Kurt Hindenburg


On March 4th, 2017, 10:56 p.m. UTC, Peter Wu wrote:

Review request for Konsole and Kurt Hindenburg.
By Peter Wu.

Updated March 4, 2017, 10:56 p.m.

Bugs: 372991
Repository: kpty

Description

On Linux, even if slave activity is detected on a master fd, FIONREAD
can still return zero available bytes in the buffer. Previously this
would prevent further signals from being emitted even if new IO arrived
(since the readNotifier is disabled) which in its turn prevented the
Konsole output from being updated.

A race condition in the kernel is suspected, the first known broken
kernel is v4.1.10-89-g5eb491ba5d06.

BUG: 372991

Testing

Tested in conjunction with konsole v16.12.1-60-g151215a9 with this debug patch applied:

diff --git a/src/kptydevice.cpp b/src/kptydevice.cpp
index 92b443b..4dfcd02 100644
--- a/src/kptydevice.cpp
+++ b/src/kptydevice.cpp
@@ -273,6 +273,7 @@ struct KPtyDevicePrivate : public KPtyPrivate {
     KRingBuffer writeBuffer;
 };

+#include <cstdio>
 bool KPtyDevicePrivate::_k_canRead()
 {
     Q_Q(KPtyDevice);
@@ -310,6 +311,9 @@ bool KPtyDevicePrivate::_k_canRead()
         // select() will trigger again anyway if an EOF condition was found, and
         // only then we will accept it.
         if (!available && !maybeEof) {
+            FILE *fp = fopen("/tmp/EOF", "a");
+            fprintf(fp, "Maybe EOF!?\n");
+            fclose(fp);
             maybeEof = true;
             return true;
         } else if (available) {

Indeed, the /tmp/EOF file is being written and the Konsole output no longer "hangs".

Closing a tab (via EOF in bash or closing the tab) somehow does not trigger this debug print, perhaps the watcher is disabled elsewhere. (This is an observation and not a problem.)

Diffs

  • src/kptydevice.cpp (22233a505d32d988795839cb592098c38f7fab33)

View Diff

--===============4823119506918845884==--