[gvfs] channel: Set sockets as nonblocking to prevent deadlocks when copying



commit 0496270865f90e35b5d89f7fb3e7da2cc6aad942
Author: Ondrej Holy <oholy redhat com>
Date:   Fri Aug 11 13:05:27 2017 +0200

    channel: Set sockets as nonblocking to prevent deadlocks when copying
    
    The channel socket pair is not set as nonblocking currently, which may cause
    deadlocks in some cases (e.g. in-mount copy over read-write fallback), because
    g_output_stream_write_async may block. This issue appears after increasing max
    size of buffer in read channel:
    https://bugzilla.gnome.org/show_bug.cgi?id=773826
    
    Set channel sockets as nonblocking to be sure that _async methods don't block.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=785391

 daemon/gvfschannel.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
---
diff --git a/daemon/gvfschannel.c b/daemon/gvfschannel.c
index 021d292..c358660 100644
--- a/daemon/gvfschannel.c
+++ b/daemon/gvfschannel.c
@@ -209,7 +209,11 @@ g_vfs_channel_init (GVfsChannel *channel)
       channel->priv->cancellable = g_cancellable_new ();
       channel->priv->reply_stream = g_unix_output_stream_new (socket_fds[0], FALSE);
       channel->priv->remote_fd = socket_fds[1];
-      
+
+      /* Set as nonblocking to be sure that _async methods don't block. */
+      fcntl (socket_fds[0], F_SETFL, O_NONBLOCK);
+      fcntl (socket_fds[1], F_SETFL, O_NONBLOCK);
+
       start_request_reader (channel);
     }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]