TCP connection closure


Hello all,

I am having trouble with what to do with a TCP client channel which has been created by a device which and on subsequent closure by the device with an unclean response from the server application. The symptoms are as follows:

OS Firmware 7.2
WIP Plugin

In our project I use a combination of wip_TCPClientCreateOpts , wip_close and WIP_COPT_FINALIZER to control the opening and closing of a TCP connection.

What I have discovered is the following problem:

  • The device closes channel with wip_close
  • Using Wireshark to monitor the TCP communication I see a FIN ACK from the device
  • The server responds with an ACK (as expected)
  • The write part of the channel is now closed to the server.
  • In the device I receive a finalised event (ref: WIP_COPT_FINALIZER)
  • I now consider this channel closed
  • At a later point in time I open a channel again repeating from the 1st step listed above.

A problem that I am seeing with this sequence is that after x repeated connections/closures (i believe this to be 8 ref: WIP_NET_OPT_SOCK_MAX) and when I try to open another channel again, the wip_TCPClientCreateOpts function returns stating that it cannot create another channel. At this point our device just keeps trying to close any possibly open channel followed by trying to open a channel again (time delayed). The device never appears to manage to create a socket again from this point onwards.

I believe the problem occurs as a result of the device processed the wip_closed/FIN ACK/ACK ‘d successfully but there is no FIN ACK/ACK from the server to close the read part of the channel hence leaving channel resources allocated in the device. This in turn means that after WIP_NET_OPT_SOCK_MAX channels have been created wip_TCPClientCreateOpts is unable to create any more channels.

If I use a utility that closes the channel both ways i.e. device wip_closed/FIN ACK/ACK ‘d successfully followed by FIN ACK/ACK from the server then the device never fails to create a channel.

My question is, if I have un released channel resources is there a way to monitor these un released resources and clear them if too many un closed channels have accumulated?

I do realise that I can use wip_shutdown to close both directions of a channel but I would rather give the server the opportunity to close the channel cleanly.

I have also recently realized that I believe the device is being left with connections in the FIN_WAIT_2 state. Is there a way to monitor channels left in this state and forcibly close them after a time period or, is there a timeout period I can set for this state when using the wip_TCPClientCreateOpts function.





From your description it seems that the server diddn’t send the FIN_ACK message to the client and resulting in the FIN_WAIT_2 state .So may be you can try changing some settings on the server side such that FIN_WAIT_2 timeouts after a specified time period or just try to set a lower value for WIP_NET_OPT_TCP_KEEP_INTVL(this option
is available in the latest WIP guide, not sure if it is available in the older versions) to decrease the FIN_WAIT_2 state period.