diff --git a/src/emqx_channel.erl b/src/emqx_channel.erl index e0789382a..da412126e 100644 --- a/src/emqx_channel.erl +++ b/src/emqx_channel.erl @@ -946,7 +946,10 @@ handle_info({sock_closed, Reason}, Channel = end; handle_info({sock_closed, Reason}, Channel = #channel{conn_state = disconnected}) -> - ?LOG(error, "Unexpected sock_closed: ~p", [Reason]), + %% Since sock_closed messages can be generated multiple times, + %% we can simply ignore errors of this type in the disconnected state. + %% e.g. when the socket send function returns an error, there is already + %% a tcp_closed delivered to the process mailbox {ok, Channel}; handle_info(clean_acl_cache, Channel) -> diff --git a/src/emqx_connection.erl b/src/emqx_connection.erl index 69337adf2..ffec9055e 100644 --- a/src/emqx_connection.erl +++ b/src/emqx_connection.erl @@ -685,7 +685,10 @@ handle_info(activate_socket, State = #state{sockstate = OldSst}) -> end; handle_info({sock_error, Reason}, State) -> - Reason =/= closed andalso ?LOG(error, "Socket error: ~p", [Reason]), + case Reason =/= closed andalso Reason =/= einval of + true -> ?LOG(warning, "socket_error: ~p", [Reason]); + false -> ok + end, handle_info({sock_closed, Reason}, close_socket(State)); handle_info(Info, State) ->