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

enotconn error occured when call ‘inet:peername(Sock)’ in esockd_acceptor.erl sometimes #9

Closed
emqplus opened this issue Apr 9, 2015 · 3 comments
Assignees
Labels
Milestone

Comments

@emqplus
Copy link
Contributor

emqplus commented Apr 9, 2015

Possible reason:

http://erlang.org/pipermail/erlang-questions/2012-June/067331.html

@emqplus
Copy link
Contributor Author

emqplus commented Apr 9, 2015

Reason:

The client was closing its connection immediately after opening with the SO_LINGER option
enabled, and a timeout of 0 seconds. This resulted in a RST with no FIN.
So, even if I called peername immediately after accept, with option
{exit_on_close, false} set, it always returned enotconn.

@emqplus
Copy link
Contributor Author

emqplus commented Apr 9, 2015

diff --git a/src/esockd_connection_sup.erl b/src/esockd_connection_sup.erl
index 7ac155d..9ec37bf 100644
--- a/src/esockd_connection_sup.erl
+++ b/src/esockd_connection_sup.erl
@@ -140,22 +140,26 @@ handle_call({start_connection, _SockArgs}, _From, State = #state{curr_cli

 handle_call({start_connection, SockArgs = {_, Sock, _SockFun}}, _From,
             State = #state{mfargs = MFArgs, curr_clients = Count, access_rules = Rules}) ->
-    {ok, {Addr, _Port}} = inet:peername(Sock),
-    case allowed(Addr, Rules) of
-        true ->
-            case catch esockd_connection:start_link(SockArgs, MFArgs) of
-                {ok, Pid} when is_pid(Pid) ->
-                    put(Pid, true),
-                    {reply, {ok, Pid}, State#state{curr_clients = Count+1}};
-                ignore ->
-                    {reply, ignore, State};
-                {error, Reason} ->
-                    {reply, {error, Reason}, State};
-                What ->
-                    {reply, {error, What}, State}
-    case inet:peername(Sock) of
-        {ok, {Addr, _Port}} ->
-            case allowed(Addr, Rules) of
-                true ->
-                    case catch esockd_connection:start_link(SockArgs, MFArgs) of
-                        {ok, Pid} when is_pid(Pid) ->
-                            put(Pid, true),
-                            {reply, {ok, Pid}, State#state{curr_clients = Count+1}};
-                        ignore ->
-                            {reply, ignore, State};
-                        {error, Reason} ->
-                            {reply, {error, Reason}, State};
-                        What ->
-                            {reply, {error, What}, State}
-                    end;
-                false ->
-                    {reply, {error, fobidden}, State}
           end;
-        false ->
-            {reply, {error, fobidden}, State}
-        {error, Reason} ->
-            {reply, {error, Reason}, State}
   end;

@emqplus emqplus closed this as completed Apr 9, 2015
@emqplus emqplus added the bug label Apr 9, 2015
@emqplus emqplus added this to the 2.3.0 milestone Apr 9, 2015
@emqplus emqplus self-assigned this Apr 9, 2015
@larrymeng
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants