GNOME Bugzilla – Bug 690449
tunneling VNC through SSH is broken
Last modified: 2013-01-06 11:34:37 UTC
On my Debian Wheezy amd64 system, VNC tunnelling through SSH does not work. When I launch the connection, Vinagre waits for 15 seconds then fails with "An error occurred. Connection to host $HOST failed". I can deterministically reproduce this with Vinagre 3.4.2 (from Debian) and 3.6.2 (locally compiled). This is not a duplicate of #644432, because the failure is deterministic and does not involve SIGHUP. I isolated the cause of the problem: in vinagre-ssh.c, function look_for_stderr_errors(), the call to g_data_input_stream_read_line() is blocking. It waits until the SSH command line exits after the 15 seconds delay, and the tunnel is therefore not established. This read call should be non-blocking: in function vinagre_ssh_connect(), before calling look_for_stderr_errors(), there is a call to fcntl() with O_NONBLOCK flag. But for some reason this seems to be ineffective. I guess this has to do with some Glib internals when creating the GInputStreams. Note that I could reproduce the bug against both Glib 2.32 and 2.34.
Created attachment 232150 [details] [review] Use GPollableInputStream when checking for SSH errors, in order to prevent a blocking read
I attached a patch that fixes the issue for me. It uses GPollableInputStream to determine if input is available on the SSH error stream (only on Un*x systems, I left the current behavior unchanged on Windows since GPollableInputStream is not implemented there). As a side effect, the patch fixes a minor memory leak in vinagre-ssh.c:look_for_stderr_errors() where the "line" variable was not correctly freed in all cases.
Comment on attachment 232150 [details] [review] Use GPollableInputStream when checking for SSH errors, in order to prevent a blocking read Thanks for the patch. I pushed it to master and gnome-3-6 branches as commits 920f41e874368eb46f52bfe8d9755cde5b11faa6 and 5f0688183974e3d5d055b8d136c1ac7ee6e3041c.