Skip to content

Zero Length Data and SOCK_FIN_WAIT

February 28, 2016

On the browser side of the server I have two issues that i will call protocol problems. I have kludged around them but they are there.
First, pretty often I get a session established with 0 data. Sometimes if I retry a few times the data will show up but sometimes it wont.
Second, after dealing with a session i issue a disconnect but the socket instead of closing goes into SOCK_FIN_WAIT waiting for the client to terminate. Again, sometimes this will clear up and other times it won’t in which case i have to CLOSE the socket myself.

In both cases I have adopted a pattern of allowing a some retries then forcing the matter. For the 0 length data I cycle on the spot trying 5 times at 20ms intervals. For the SOCK_FIN_WAIT I allow 2 retries that are 30ms or so apart – basically 100 ms in each case. I have tried just closing the session immediately in each situation but that resulted in hung browsers once in a while. Right now, there’s no visible symptoms to the user.

I don’t see any way around retrying for 0 length. It happens pretty often when the browser is coming from the public internet. Sometimes the data shows up after a few retries, some times it doesn’t. I notice today, though, that the 0 lengths are inevitably followed by SOCK_FIN_WAIT situations which don’t resolve. In this case at least I might be able to close the socket in the first place rather than try the disconnect.

Another approach, which i could do if i had multiple browser sockets would be what i do with telnet – if there’s a session with no data(or in the case of telnet no carriage return) i just move on with polling the other sockets. I don’t get excited about it, i just time it out if it goes on too long – in telnet’s case that’s two minute, for the browser i could tune it but probably 1/2 second or something. If I have multiple sockets open it won’t matter too much and i guess this would be MORE responsive than spinning in place on the one socket.

Below is my serial trace for a browse on my local LAN. I looked hard at a sequence that was coming from australia over the internet and i found that i invariably had to retry a couple of times to get the data and that I got the SFW fail almost every time.

//first we get 0 length data
re-size re-size re-size re-size re-size **sock=0, rsz=0 flushing 0
done
>
//now we get GET request and we send the form 
**sock=0, rsz=371 GET / HTTP/1.1
5,999
IP: 192.168.1.93,slot 5,secret 107
flushing 371
done
>
//now we get the favico request which we NAK
**sock=0, rsz=312
GET /favicon.ico
flushing 312
done
>
//now another 0 data session
re-size re-size re-size re-size re-size **sock=0, rsz=0 flushing 0
done
>
//we end with a SOCK_FIN_WAIT state that never resolves
SOCK_FIN_WAIT: ignoring
SOCK_FIN_WAIT: ignoring
SOCK_FIN_WAIT: lost patience, closing
re-size **sock=0, rsz=384
GET /?G=123 HTTP
Guess: 1.132.96.120,slot 2,secret 703
flushing 384
done
>
SOCK_FIN_WAIT: ignoring
SOCK_FIN_WAIT: ignoring
SOCK_FIN_WAIT: lost patience, closing
re-size re-size re-size re-size re-size **sock=0, rsz=0
flushing 0
done
>
SOCK_FIN_WAIT: ignoring
SOCK_FIN_WAIT: ignoring
SOCK_FIN_WAIT: lost patience, closing
re-size re-size re-size re-size re-size **sock=0, rsz=0
flushing 0
done
>
SOCK_FIN_WAIT: ignoring
SOCK_FIN_WAIT: ignoring
SOCK_FIN_WAIT: lost patience, closing
re-size re-size re-size re-size re-size **sock=0, rsz=0
flushing 0
done
>
SOCK_FIN_WAIT: ignoring
SOCK_FIN_WAIT: ignoring
SOCK_FIN_WAIT: lost patience, closing
re-size re-size re-size **sock=0, rsz=358
GET /?G=190 HTTP
Guess: 1.132.96.120,slot 2,secret 703
flushing 358
done
>
Advertisements

From → Olduino/Z, web server

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: