[6.x] problem with AIO, non-blocking sockets on freebSD and IE7 on windows.




If one has an event-driven process that accepts tcp connections, one needs to set eh non-blocking socket option and use kqueue or similar to schedule work.

This is ok for data transfers, however when it comes to the close() call there is a problem. The problem in in the following code in so_close()


if (so->so_options & SO_LINGER) {
if ((so->so_state & SS_ISDISCONNECTING) &&
(so->so_state & SS_NBIO))
goto drop;
while (so->so_state & SS_ISCONNECTED) {
error = tsleep(&so->so_timeo,
PSOCK | PCATCH, "soclos", so->so_linger * hz);
if (error)
break;
}
}
}

drop:
[ continues on to destroy socket ]


because SS_NBIO is set, the socket acts as if SO_LINGER was set, with a timeout of 0.
the result of this, is the following behaviour:

========================================== The first + last packet output is below:
========================================== Source Destination Info
172.20.51.115 172.20.3.43 2597 > http [SYN] Seq=0 Len=0 172.20.3.43 172.20.51.115 http > 2597 [SYN, ACK] Seq=0 Ack=1 Len=0 172.20.51.115 172.20.3.43 2597 > http [ACK] Seq=1 Ack=1 Len=0
172.20.51.115 172.20.3.43 POST http://creative.gettyimages.com/source/<truncated>
HTTP/1.1
172.20.51.115 172.20.3.43 HTTP
172.20.3.43 172.20.51.115 http > 2597 [ACK] Seq=1 Ack=1261 Len=0

---------------

172.20.3.43 172.20.51.115 http > 2597 [ACK] Seq=1 Ack=13729 Len=0
172.20.51.115 172.20.3.43 HTTP
172.20.3.43 172.20.51.115 HTTP/1.0 407 Proxy Authentication Required
(text/html)
172.20.3.43 172.20.51.115 HTTP
172.20.3.43 172.20.51.115 http > 2597 [FIN, ACK] Seq=1858 Ack=13729 Len=0
172.20.51.115 172.20.3.43 2597 > http [ACK] Seq=13731 Ack=1859 Len=0
172.20.3.43 172.20.51.115 http > 2597 [RST] Seq=1 Len=0
172.20.3.43 172.20.51.115 http > 2597 [RST] Seq=1859 Len=0


The ACK that comes from the client is wquite legal and in fact a FIN should follow.
however we react to it by sending a reset.

This makes IE7 throw a "generic IE error page". Even though it has all the information it needs.
Less that a good result for the user.

The answer is to NOT destroy the socket immediately, but to schedule it for self destruction
in FIN_WAIT_1_TIME seconds (or so_linger secs) or when the FIN turns up, whichever occurs first.

however so_close is in the wrong layer to decide to do this I think... socket code in general
has no timer related stuff.. TCPhas timers, so I thin it would require a new call into TCP
to tell it to put the session in question onto a (new) timer..

thoughts anyone?

Julian






_______________________________________________
freebsd-net@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "freebsd-net-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: how to use wait_event_interruptible_timeout
    ... I have a kernel module where I have ... opened multiple tcp connections. ... i want my process to sleep. ... so that whenever data is available on any socket (tcp ...
    (Linux-Kernel)
  • Re: kernel panic: page fault
    ... It looks like we have an inconsistency in how we handle the recycling of timewait state for an inpcb that is still present. ... the problem is how to handle sockets with attached inpcbs that represent closed or time wait TCP connections. ... This can happen if shutdownis called on a socket, kicking the TCP state engine into a close cycle, rather than a reset. ... This is related to the inpcb without twtcp case, where we recycle the twtcp, but can't recylce the inpcb immediately because there's still an fd reference to the socket, and hence a socket reference to the inpcb. ...
    (freebsd-current)
  • C# Raw Socket Issues starting TCP Connections
    ... I am working on starting and managing TCP connections manually. ... read incomming data if I use IOControl and set the socket SIO_RCVALL. ... some reason the Socket replys with a RST with out me doing anything. ... promiscious mode that it seems to apply to other sockets running in ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: My server sometimes goes deaf to certain hosts
    ... If your program is blocked on a pipe or unix socket, ... new TCP connections because it won't call 'accept' until the blocking ... so you are saying that the listening process might be blocking ...
    (comp.os.linux.development.apps)
  • Re: [bug] stuck localhost TCP connections, v2.6.26-rc3+
    ... part of the handshake is received, but the socket ... isn't put on the accept queue until a real data packet arrives. ... I did run tests where the server died in between the handshake being ... can display apparently large timer values when the timer is elapsed ...
    (Linux-Kernel)