The message
{tcp_closed, Socket}
Will be delivered to the riakc_pb_socket process, at line 1026, and then the disconnect function will notify any requests of the closure by sending
{error, disconnected}
If auto_reconnect is set, the riakc_pb_socket process will attempt to re-establish the connection.
Your code will see the disconnected error in response to some request to the server.
Excerpts from riakc_pb_socket.erl:
Line 1025:
handle_info({tcp_closed, _Socket}, State) ->
disconnect(State);
The disconnect function:
%% @private
%% Disconnect socket if connected
disconnect(State) ->
%% Tell any pending requests we've disconnected
_ = case State#state.active of
undefined ->
ok;
Request ->
send_caller({error, disconnected}, Request)
end,
%% Make sure the connection is really closed
case State#state.sock of
undefined ->
ok;
Sock ->
gen_tcp:close(Sock)
end,
%% Decide whether to reconnect or exit
NewState = State#state{sock = undefined, active = undefined},
case State#state.auto_reconnect of
true ->
%% Schedule the reconnect message and return state
erlang:send_after(State#state.reconnect_interval, self(), reconnect),
{noreply, increase_reconnect_interval(NewState)};
false ->
{stop, disconnected, NewState}
end.