aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2019-09-22 16:10:10 +0200
committerLoïc Hoguin <[email protected]>2019-09-22 16:46:45 +0200
commitdbb6bab31e09a6810331ffcb018e973b2bbe9fad (patch)
tree08d7f95fdaf8d79a2aa483f25463a1541d1e9568
parent37b771210f94b9b692d0417d79483b9927d46ba2 (diff)
downloadgun-dbb6bab31e09a6810331ffcb018e973b2bbe9fad.tar.gz
gun-dbb6bab31e09a6810331ffcb018e973b2bbe9fad.tar.bz2
gun-dbb6bab31e09a6810331ffcb018e973b2bbe9fad.zip
Cancel the existing keepalive when switching protocols
-rw-r--r--src/gun.erl9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/gun.erl b/src/gun.erl
index 6efca0b..8eaa55e 100644
--- a/src/gun.erl
+++ b/src/gun.erl
@@ -1305,10 +1305,13 @@ commands([{switch_protocol, Protocol0}], State0=#state{
end,
{StateName, ProtoState} = Protocol:init(Owner, Socket, Transport, ProtoOpts),
EvHandlerState = EvHandler:protocol_changed(#{protocol => Protocol:name()}, EvHandlerState0),
- State = State0#state{protocol=Protocol, protocol_state=ProtoState, event_handler_state=EvHandlerState},
+ %% We cancel the existing keepalive and, depending on the protocol,
+ %% we enable keepalive again, effectively resetting the timer.
+ State = keepalive_cancel(active(State0#state{protocol=Protocol, protocol_state=ProtoState,
+ event_handler_state=EvHandlerState})),
case Protocol:has_keepalive() of
- true -> {next_state, StateName, keepalive_timeout(active(State))};
- false -> {next_state, StateName, keepalive_cancel(active(State))}
+ true -> {next_state, StateName, keepalive_timeout(State)};
+ false -> {next_state, StateName, State}
end;
%% Perform a TLS handshake.
commands([TLSHandshake={tls_handshake, _, _}], State) ->