Skip to contentSkip to conversation

io: fix handling of EOF / error conditions in websock GSource

PATCH Superseded Daniel P. Berrangé 2 participants 3 messages Feb 20, 2019 – Feb 21, 2019

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 io: fix handling of EOF / error conditions in websock GSource

We were never reporting the G_IO_HUP event when an end of file was hit on the websocket channel.

We also ddn't report G_IO_ERR when we hit a fatal error processing the websocket protocol.

The latter in particular meant that the chardev code would not notice when an eof/error was encountered on the websocket channel, unless the guest OS happened to trigger a write operation.

This meant that once the first client had quit, the chardev would never listen to accept a new client.

Fixes launchpad bug 1816819

---
 io/channel-websock.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
io/channel-websock.c +7 -1
index dc43dc6bb9..fc4c3dcaa5 100644
@@ -1225,12 +1225,18 @@ qio_channel_websock_source_check(GSource *source)
     QIOChannelWebsockSource *wsource = (QIOChannelWebsockSource *)source;
     GIOCondition cond = 0;
 
-    if (wsource->wioc->rawinput.offset || wsource->wioc->io_eof) {
+    if (wsource->wioc->rawinput.offset) {
         cond |= G_IO_IN;
     }
     if (wsource->wioc->encoutput.offset < QIO_CHANNEL_WEBSOCK_MAX_BUFFER) {
         cond |= G_IO_OUT;
     }
+    if (wsource->wioc->io_eof) {
+        cond |= G_IO_IN | G_IO_HUP;
+    }
+    if (wsource->wioc->io_err) {
+        cond |= G_IO_IN | G_IO_ERR;
+    }
 
     return cond & wsource->condition;
 }
Signature · 1 line
2.20.1
#1 lore raw

Hi Daniel,

Quoted 4 lines · Daniel P. Berrangé

We were never reporting the G_IO_HUP event when an end of file was hit on the websocket channel.

We also ddn't report G_IO_ERR when we hit a fatal error processing the

"didn't report"

Quoted 22 lines

websocket protocol.

The latter in particular meant that the chardev code would not notice when an eof/error was encountered on the websocket channel, unless the guest OS happened to trigger a write operation.

This meant that once the first client had quit, the chardev would never listen to accept a new client.

Fixes launchpad bug 1816819

---
 io/channel-websock.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
io/channel-websock.c +0 -0
index dc43dc6bb9..fc4c3dcaa5 100644
@@ -1225,12 +1225,18 @@ qio_channel_websock_source_check(GSource *source)
     QIOChannelWebsockSource *wsource = (QIOChannelWebsockSource *)source;
     GIOCondition cond = 0;

io/channel-websock.c qio_channel_websock_source_check(GSource *source) · line 1235

Quoted 10 lines
io/channel-websock.c +3 -1
 
-    if (wsource->wioc->rawinput.offset || wsource->wioc->io_eof) {
+    if (wsource->wioc->rawinput.offset) {
         cond |= G_IO_IN;
     }
     if (wsource->wioc->encoutput.offset < QIO_CHANNEL_WEBSOCK_MAX_BUFFER) {
         cond |= G_IO_OUT;
     }
+    if (wsource->wioc->io_eof) {
+        cond |= G_IO_IN | G_IO_HUP;

Shouldn't this be:

           cond |= G_IO_HUP;

io/channel-websock.c qio_channel_websock_source_check(GSource *source) · line 1238

Quoted 3 lines
io/channel-websock.c +3 -0
+    }
+    if (wsource->wioc->io_err) {
+        cond |= G_IO_IN | G_IO_ERR;

Ditto:

           cond |= G_IO_ERR;
Quoted 5 lines
io/channel-websock.c +1 -0
+    }
 
     return cond & wsource->condition;
 }
#2 lore raw
Quoted 45 lines · Philippe Mathieu-Daudé

Hi Daniel,

Quoted 4 lines · Daniel P. Berrangé

We were never reporting the G_IO_HUP event when an end of file was hit on the websocket channel.

We also ddn't report G_IO_ERR when we hit a fatal error processing the

"didn't report"

Quoted 22 lines

websocket protocol.

The latter in particular meant that the chardev code would not notice when an eof/error was encountered on the websocket channel, unless the guest OS happened to trigger a write operation.

This meant that once the first client had quit, the chardev would never listen to accept a new client.

Fixes launchpad bug 1816819

---
 io/channel-websock.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
io/channel-websock.c +0 -0
index dc43dc6bb9..fc4c3dcaa5 100644
@@ -1225,12 +1225,18 @@ qio_channel_websock_source_check(GSource *source)
     QIOChannelWebsockSource *wsource = (QIOChannelWebsockSource *)source;
     GIOCondition cond = 0;

io/channel-websock.c qio_channel_websock_source_check(GSource *source) · line 1235

Quoted 10 lines
io/channel-websock.c +3 -1
 
-    if (wsource->wioc->rawinput.offset || wsource->wioc->io_eof) {
+    if (wsource->wioc->rawinput.offset) {
         cond |= G_IO_IN;
     }
     if (wsource->wioc->encoutput.offset < QIO_CHANNEL_WEBSOCK_MAX_BUFFER) {
         cond |= G_IO_OUT;
     }
+    if (wsource->wioc->io_eof) {
+        cond |= G_IO_IN | G_IO_HUP;

Shouldn't this be:

Quoted 1 line
           cond |= G_IO_HUP;

With regular poll() on FD I believe you typically get POLLIN | POLLHUP as a pair.

Quoted 8 lines

io/channel-websock.c qio_channel_websock_source_check(GSource *source) · line 1238

Quoted 4 lines
io/channel-websock.c +3 -0
+    }
+    if (wsource->wioc->io_err) {
+        cond |= G_IO_IN | G_IO_ERR;

Ditto:

           cond |= G_IO_ERR;

And I just followed the same practice here.

Quoted 3 lines

io/channel-websock.c qio_channel_websock_source_check(GSource *source) · line 1241

Quoted 3 lines
io/channel-websock.c +1 -0
+    }
 
     return cond & wsource->condition;

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|