Skip to content
Browse files

Fix to close a tcp socket properly in any cases

  • Loading branch information...
1 parent c9b4778 commit 9b984e5d20ba49aa1847a38cabd603a4c5ce983c @mocchira mocchira committed Feb 18, 2014
Showing with 12 additions and 6 deletions.
  1. +3 −0 src/leo_rpc_client_conn.erl
  2. +9 −6 test/leo_rpc_tests.erl
View
3 src/leo_rpc_client_conn.erl
@@ -131,6 +131,7 @@ handle_info({tcp_error, Socket, Reason}, #state{pid_from = From} = State) ->
{noreply, State#state{pid_from = undefined, socket = undefined, nreq = 0}};
handle_info({tcp_closed, _Socket}, State) ->
+ terminate(tcp_closed, State),
case State#state.reconnect_sleep of
0 ->
void;
@@ -144,9 +145,11 @@ handle_info({connection_ready, Socket}, #state{socket = undefined} = State) ->
{noreply, State#state{socket = Socket}};
handle_info(stop, State) ->
+ terminate(stop, State),
{stop, shutdown, State};
handle_info(_Info, State) ->
+ terminate(_Info, State),
{stop, {unhandled_message, _Info}, State}.
terminate(_Reason, #state{socket = Socket}) ->
View
15 test/leo_rpc_tests.erl
@@ -100,6 +100,7 @@ tuple_(Node) ->
ok.
send_large_(Node) ->
+ {timeout, 15, begin
%% send a large-object
lists:foreach(fun(Size) ->
Bin = crypto:rand_bytes(Size),
@@ -114,10 +115,11 @@ send_large_(Node) ->
7 * 1024*1024,
8 * 1024*1024,
9 * 1024*1024,
- 10 * 1024*1024]),
- ok.
+ 10 * 1024*1024])
+ end}.
receive_large_(Node) ->
+ {timeout, 15, begin
%% receive a large-object
lists:foreach(fun(Size) ->
Bin = leo_rpc:call(Node, crypto, rand_bytes, [Size]),
@@ -131,8 +133,8 @@ receive_large_(Node) ->
7 * 1024*1024,
8 * 1024*1024,
9 * 1024*1024,
- 10 * 1024*1024]),
- ok.
+ 10 * 1024*1024])
+ end}.
-record(test, {
str :: string(),
@@ -143,6 +145,7 @@ receive_large_(Node) ->
}).
record_(Node) ->
+ {timeout, 15, begin
F = fun(X) -> X * X end,
Bin = crypto:rand_bytes(10 * 1024*1024),
T = #test{
@@ -153,8 +156,8 @@ record_(Node) ->
func = F
},
Serialized = term_to_binary(T),
- ?assertEqual(T, leo_rpc:call(Node, 'erlang', 'binary_to_term', [Serialized])),
- ok.
+ ?assertEqual(T, leo_rpc:call(Node, 'erlang', 'binary_to_term', [Serialized]))
+ end}.
others_(Node) ->
%% Others

0 comments on commit 9b984e5

Please sign in to comment.
Something went wrong with that request. Please try again.