Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Bug reports ➜ TCP not closing correctly (FIN_WAIT_2)

TCP not closing correctly (FIN_WAIT_2)

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Liet   (1 post)  Bio
Date Thu 12 Aug 2004 04:53 AM (UTC)
Message
I noticed this while writing my own mud server from scratch. Its mostly a coding exercise so while I was trying to get my async connections shut down properly I noticed mushclient was leaving its connections in FIN_WAIT_2 and CLOSE_WAIT. This only happens when using a "quit" command (ie the mud initiates closing the connection).

Quit command (server disconnecting client):

Proto Local Address Foreign Address State
TCP envy:4000 localhost:4977 FIN_WAIT_2
TCP envy:4977 localhost:4000 CLOSE_WAIT

And then when mushclient is closed netstat reports what it should have originally:

TCP envy:4000 localhost:4977 TIME_WAIT

Regular telnet and zMud both don't exhibit this behavior and it leaves its connection in close_wait for non-local servers as well so I'm pretty sure it's not my server. While this isn't the end of the world, FIN_WAIT_2 can have a fairly long timeout.
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #1 on Sun 15 Aug 2004 01:41 AM (UTC)
Message
Strangely enough, I am also writing my own MUD server from scratch. I hadn't noticed what you said, but you are right.

It must be closing the connection the wrong way, I'll look into it.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by godefroi   (17 posts)  Bio
Date Reply #2 on Mon 16 Aug 2004 06:59 PM (UTC)

Amended on Mon 16 Aug 2004 07:01 PM (UTC) by godefroi

Message
A socket gets into CLOSE_WAIT when the remote side sends a FIN and the local side sends an ACK, but has not yet sent it's FIN.

A socket gets into FIN_WAIT_2 when the local side closes the socket and sends a FIN (FIN_WAIT_1) and then recieves an ACK for that FIN but has not yet recieved a FIN from the remote side.

See http://www.vs.inf.ethz.ch/edu/WS0102/VS/TCP-State-Diagram.html for details.

That said, I can see how MC could be leaving sockets in CLOSE_WAIT, but I can't see how a socket can get into FIN_WAIT_2 if the remote side closed the connection first. It shouldn't be possible.
Top

Posted by Nick Gammon   Australia  (23,165 posts)  Bio   Forum Administrator
Date Reply #3 on Wed 18 Aug 2004 09:43 PM (UTC)

Amended on Wed 18 Aug 2004 10:23 PM (UTC) by Nick Gammon

Message
I think MUSHclient sets the "no linger" flag on connections, thus after receiving the FIN it sends an ACK but doesn't send the final FIN.

I dumped a session (tcpdump port 4000):


07:35:10.546129 client.2468 > server.4000: P 18:24(6) ack 2680 win 8760

07:35:10.546222 server.4000 > client.2468: . ack 24 win 5840

07:35:10.595955 server.4000 > client.2468: P 2680:2901(221) ack 24 win 5840

07:35:10.596047 server.4000 > client.2468: F 2901:2901(0) ack 24 win 5840

07:35:10.596497 client.2468 > server.4000: . ack 2902 win 8539


I typed "quit" which was sent (first line), the server responded "Your surroundings begin to fade..." (second line) and "We await your return, Nick..." (third line), then the server sends FIN (fourth line), which the client ACKs (fifth line). After that, nothing.

I think you are reading the diagram from the wrong side. Look at the bottom-left corner and you will see:


  • ESTAB -> Server closes the session and sends FIN. Goes into FIN WAIT-1

  • FIN-WAIT-1 -> Server receives ACK of FIN, goes into FIN WAIT-2



At this point MUSHclient forcibly disconnects the connection (due to NO_LINGER being set) and drops its end. Thus the server is still in FIN-WAIT-2.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by godefroi   (17 posts)  Bio
Date Reply #4 on Thu 19 Aug 2004 11:10 PM (UTC)
Message
I thought the CLIENT was stuck in FIN_WAIT_2.

Man, was I confused.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


21,232 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.