[erlang-questions] ssl_closed not always received
Mon Apr 11 18:57:56 CEST 2016
On 04/11/2016 06:43 PM, Khitai Pang wrote:
> On 2016/4/11 17:52, Loïc Hoguin wrote:
>> On 04/11/2016 11:43 AM, Khitai Pang wrote:
>>> On 2016/4/11 17:24, Loïc Hoguin wrote:
>>>> On 04/11/2016 10:23 AM, Roger Lipscombe wrote:
>>>>> On 10 April 2016 at 22:34, Khitai Pang <khitai.pang@REDACTED>
>>>>>> How to make sure that the server process always get ssl_closed
>>>>>> when the
>>>>>> client process on a remote host quits?
>>>>> In the general case, you *can't*. This is due to the vagaries of TCP.
>>>>> To close a socket, the client will send a FIN packet to the server. If
>>>>> the network connection is lost (consider simply unplugging the cable),
>>>>> then the FIN will *never* arrive. If you need to know when the client
>>>>> has gone away, either implement some kind of application-level
>>>>> keepalive or enable TCP keepalive.
>>>> You need a bi-directional ping mechanism at the application level. TCP
>>>> keepalive is not always enough.
>>> How about this? The client sends a heartbeat message to the server
>>> every 2 minutes and the server replies with a heartbeat ack. The server
>>> deems the connection as lost if no heartbeat received in 2 minutes and
>>> the client deems the connection as lost if heartbeat ask is not received
>>> in 2 minutes. This sounds like uni-directional to me but would it
>> All that matters is that both endpoints send a ping message. It can be
>> sent as a response.
>> One important point is that the client and server agree on timeouts
>> (this can be part of the protocol handshake or explicitly defined in
>> the implementation, they just need to agree on it). Note that there's
>> two timeouts: one for the client, and one for the server. They don't
>> have to match.
> By non-matching timeouts on client an server do you mean that we should
> give some grace time to the client? e.g. the client sends a message
> every 5 minutes but the server deems the connection as lost if no
> message is received in 6 minutes?
I mean the client may consider the server disconnected if it hears
nothing for X seconds, while the server may consider the client
disconnected if it hears nothing for Y seconds.
Then, you're right, there's also Z, which is the interval between
client-initiated pings. But that one can be determined from X and Y.
Author of The Erlanger Playbook,
A book about software development using Erlang
More information about the erlang-questions