Rajiv
Rajiv

Reputation: 179

FIN & RST set in socket communication

There is existing socket communication with TLS 1.2 enabled for which i have included one-way/two-way support , on doing so i have observed frequent reset in socket . While analyzing the packets using wire shark observed FIN,ACK & RST flag sent which i believe the reason for getting reset or aborting the connection .

My queries:

  1. During the socket conversation i believe , at many occasion i observer EOFexcetpion while attempting to readObject(). Can this lead to socket reset or disconnect.

  2. In case i want the socket connection to be permanently connected , how can i ignore FIN & RST flag and keep up the socket connection permanent ?

  3. Is it efficient whenever socket finds idle then to disconnect . Is it when RST or FIN flag is passed ?

Upvotes: 0

Views: 1773

Answers (2)

sk23
sk23

Reputation: 210

Is it efficient whenever socket finds idle then to disconnect

yes it is efficient to disconnect or dismantle the socket for idle connections. If idle connections were not dismantled, then as new connections are initiated, the connections (socket connections) continue to remain and consume system resources/memory. Additionally each socket connection is on a new port, so as new connections keep coming in (if your server is busy like a web server for example), you continue to use up tcp ports!
Also there are two different states, FIN_WAIT_1 and FIN_WAIT_2 (refer RFC 793 for TCP Specification) So bottom line, it may not be a good idea to continue to have the socket connection to be always or permanently connected- certainly not a good idea for a busy server which is accepting lots of client traffic- the newer accepted connections will continue to remain and consume or use up local tcp ports incrementally as newer connections keep coming in...

Upvotes: -1

Jim Garrison
Jim Garrison

Reputation: 86774

...how can i ignore FIN & RST flag ...

The simple answer is that you cannot.

The protocol specifies that once you receive FIN the connection is in the process of being dismantled. You can attempt to do whatever you want, but the sender of the FIN packet is going away regardless of what you do.

The RST flag is sent back to you when you send data to an endpoint that was not expecting a packet from you, i.e. when you tried to ignore FIN.

Keeping a connection open "permanently" requires cooperation from both sides of the connection, and the connection may still fail due to timeouts if the network goes down.

Upvotes: 2

Related Questions