Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

close socket properly during session init when connection is not exist anymore #120

Merged
merged 1 commit into from
May 31, 2017

Conversation

icehess
Copy link
Contributor

@icehess icehess commented Mar 2, 2017

We observed when a connection is opened and closed in a short amount of time before even gen_smtp_server_session is started, the call to socket:peername/1 causes crash in gen_smtp_server_session and the socket remains open.

If this kind of connections happen periodically (e.g. during a Haproxy health check) , the node eventually would run out of file descriptors.

This tries to handle the call to socket:peername/1 and will close the socket if the connection is closed during initializing of a session.

of
false ->
socket:close(Socket),
ignore;
{ok, Banner, CallbackState} ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'andalso' suggests a boolean check, I would prefer to have the PeerName check and the init return handled separately. In this case you can have an init_peername({error, _}, ...) that closes the socket and a init_peername({ok, ...}, ...) that handles the init.

@mworrell
Copy link
Collaborator

Merging anyway, as the change is important enough and works well.

@mworrell mworrell merged commit 3e1e7e4 into gen-smtp:master May 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants