aboutsummaryrefslogtreecommitdiffstats
path: root/src/gun.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2019-10-08 10:39:15 +0200
committerLoïc Hoguin <[email protected]>2019-10-08 10:39:15 +0200
commit8461c8383cfdc39a50a8c7769fe8130818d5f1f5 (patch)
treeba01ac7edfe2f55b7dbbe2a4a1cdcf46cb6e364d /src/gun.erl
parent648610ae3585c9cd9ffd827ad04cb2dd2858825b (diff)
downloadgun-8461c8383cfdc39a50a8c7769fe8130818d5f1f5.tar.gz
gun-8461c8383cfdc39a50a8c7769fe8130818d5f1f5.tar.bz2
gun-8461c8383cfdc39a50a8c7769fe8130818d5f1f5.zip
Fix retrying on disconnect with retry=1
Diffstat (limited to 'src/gun.erl')
-rw-r--r--src/gun.erl24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/gun.erl b/src/gun.erl
index a72cc85..507eef7 100644
--- a/src/gun.erl
+++ b/src/gun.erl
@@ -891,6 +891,8 @@ init({Owner, Host, Port, Opts}) ->
default_transport(443) -> tls;
default_transport(_) -> tcp.
+not_connected(_, {retries, 0, normal}, State) ->
+ {stop, normal, State};
not_connected(_, {retries, 0, Reason}, State) ->
{stop, {shutdown, Reason}, State};
not_connected(_, {retries, Retries0, _}, State=#state{opts=Opts}) ->
@@ -907,9 +909,14 @@ not_connected(Type, Event, State) ->
handle_common(Type, Event, ?FUNCTION_NAME, State).
default_retry_fun(Retries, Opts) ->
+ %% We retry immediately after a disconnect.
+ Timeout = case maps:get(retry, Opts, 5) of
+ Retries -> 0;
+ _ -> maps:get(retry_timeout, Opts, 5000)
+ end,
#{
retries => Retries - 1,
- timeout => maps:get(retry_timeout, Opts, 5000)
+ timeout => Timeout
}.
domain_lookup(_, {retries, Retries, _}, State=#state{host=Host, port=Port, opts=Opts,
@@ -1427,17 +1434,10 @@ disconnect(State0=#state{owner=Owner, status=Status, opts=Opts,
KilledStreams = Protocol:down(ProtoState),
Owner ! {gun_down, self(), Protocol:name(), Reason, KilledStreams},
Retry = maps:get(retry, Opts, 5),
- case Retry of
- 0 when Reason =:= normal ->
- {stop, normal, State};
- 0 ->
- {stop, {shutdown, Reason}, State};
- _ ->
- {next_state, not_connected,
- keepalive_cancel(State#state{socket=undefined,
- protocol=undefined, protocol_state=undefined}),
- {next_event, internal, {retries, Retry - 1, Reason}}}
- end
+ {next_state, not_connected,
+ keepalive_cancel(State#state{socket=undefined,
+ protocol=undefined, protocol_state=undefined}),
+ {next_event, internal, {retries, Retry, Reason}}}
end.
disconnect_flush(State=#state{socket=Socket, messages={OK, Closed, Error}}) ->