[erlang-questions] Difference in 'close' for gen_tcp recv vs. active

Fred Hebert mononcqc@REDACTED
Wed Apr 9 15:22:01 CEST 2014


On 04/09, Jacob wrote:
> Hi,
> 
> Does the peer use close(s) or shutdown(s, SHUT_WR) to "close" the
> connection?
> 

We don't control the peer. I'm not sure what the specific call is.

> 
> It makes a difference here, whether these are FINs or RSTs. Just
> receiving a FIN from the peer will not stop the OS from accepting for
> and sending data to the peer.
> 

it is indeed a FIN for the specific dump I have. It seems to be ACKed
back (peer = AAAA, our host = BBBB):

19:10:55.748018 IP AAAA > BBBB: Flags [.], ack 385, win 62, options [nop,nop,TS val 229098891 ecr 89024950], length 0
19:10:56.070985 IP AAAA > BBBB: Flags [F.], seq 156, ack 385, win 62, options [nop,nop,TS val 229098972 ecr 89024950], length 0
19:10:56.113998 IP BBBB > AAAA: Flags [.], ack 157, win 12, options [nop,nop,TS val 89024987 ecr 229098972], length 0
19:10:56.747853 IP BBBB > AAAA: Flags [P.], seq 385:416, ack 157, win 12, options [nop,nop,TS val 89025050 ecr 229098972], length 31
19:10:56.748490 IP AAAA > BBBB: Flags [.], ack 416, win 62, options [nop,nop,TS val 229099141 ecr 89025050], length 0

It sounds like we're getting dumped into a partially closed session. I'm
guessing the peer (AAAA) gets stuck into FIN-WAIT-2, waiting for a FIN
coming from our end (BBBB), giving us a half-open connection.

What confuses me is given we have the option {exit_on_close, true} being
set explicitly, we expect Erlang to close that connection once that FIN
comes in, and not to keep half-open the way it would if we had set
{exit_on_close, false}, as set in the docs:

    {exit_on_close, Boolean}
    By default this option is set to true.
    The only reason to set it to false is if you want to
    continue sending data to the socket after a close has been
    detected, for instance if the peer has used
    gen_tcp:shutdown/2 to shutdown the write side.

Given we have it set to true, we do expect to not be able to keep
sending data after the fact. We still can, though.

> 
> If the peer uses shutdown() only you have no choice with standard
> sockets. You probably don't want to start using pcap.
> 

Again, I'm not sure I have an easy way to know there.

Thanks for your help,
Fred.



More information about the erlang-questions mailing list