With my Java testcode I am able to get the OpenSSH daemon in a state where a following client connection, e.g., an OpenSSH client, is sometimes not able to properly use X11 forwarding. More technically spoken: when doing X11 forwarding, OpenSSH sometimes attaches itself to a port (e.g., 6010) when there is still a connection (?) to 127.0.0.1:6010 (in state TIME_WAIT). As a consequence, even though OpenSSH's bind operation to ::1:6010 goes well, X11 applications are not able to connect to 127.0.0.1:6010. The problem is still present in openssh-SNAP-20050826 tested on Fedora Core 2 (2.6.8-1.521smp). One the one hand, this is probably a problem of the code in the "x11_create_display_inet" method in channel.c (port selection). On the other hand, the question is why these kind of TIME_WAIT states as seen in netstat output only occur occasionally (e.g., local: 127.0.0.1:6010 remote: 127.0.0.1:54806 - and not the other way round!). By killing SSH connections (closing socket on the client side) which were using X forwarding I was able to produce such states.
Here is a part of netstat output if everything is fine (OpenSSH is ready to forward X11 connections) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN tcp 0 0 ::1:6010 :::* LISTEN Here is a part of netstat output when things went wrong (OpenSSH thinks it is ready to forward X11 connections =) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 127.0.0.1:6010 127.0.0.1:54806 TIME_WAIT tcp 0 0 ::1:6010 :::* LISTEN
Created attachment 956 [details] Set SO_REUSEADDR for X11 sockets too Please test this patch - it sets SO_REUSEADDR for X11 listeners
Created attachment 958 [details] Different patch This patch prevents openssh from using ports which are already partially in use (on IPv4 but not on IPv6) for X11 forwarding.
I only tested the first patch (the one which sets SO_REUSEADDR on the X11 socket before binding it) and that resolves the problem. Thanks! Tested with: openssh-SNAP-20050919.tar.gz on Fedora Core 4 (2.6.12-1.1447_FC4smp).
SO_REUSEADDR patch applied and will be in OpenSSH 4.3.
Change all RESOLVED bug to CLOSED with the exception of the ones fixed post-4.4.