diff options
author | Johannes Weißl <[email protected]> | 2017-05-14 23:35:37 +0200 |
---|---|---|
committer | Johannes Weißl <[email protected]> | 2017-05-23 08:44:03 +0200 |
commit | fb4c7f27d050a167335a4274327cf1f8d8cc9aba (patch) | |
tree | d5fdc342a61dcda6f82e56b1b1a5a59e3f481206 /lib/inets/src/http_client/httpc_handler.erl | |
parent | dfbefdcc85b2785e4d2280c1b70de8fd14a6778d (diff) | |
download | otp-fb4c7f27d050a167335a4274327cf1f8d8cc9aba.tar.gz otp-fb4c7f27d050a167335a4274327cf1f8d8cc9aba.tar.bz2 otp-fb4c7f27d050a167335a4274327cf1f8d8cc9aba.zip |
Fix httpc timeout for redirects
Probably since 6153ba7 (OTP R13B04) the httpc timeout setting does not
work for redirects (when autoredirect is true). With this patch a new
timer is started for the new (redirected) requests. This means that a
simple redirected request could return after 2*timeout milliseconds.
This is the first part to fix https://bugs.erlang.org/browse/ERL-420
Diffstat (limited to 'lib/inets/src/http_client/httpc_handler.erl')
-rw-r--r-- | lib/inets/src/http_client/httpc_handler.erl | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/inets/src/http_client/httpc_handler.erl b/lib/inets/src/http_client/httpc_handler.erl index c99200777b..89c17a8679 100644 --- a/lib/inets/src/http_client/httpc_handler.erl +++ b/lib/inets/src/http_client/httpc_handler.erl @@ -1224,7 +1224,7 @@ close_socket(#session{socket = Socket, socket_type = SocketType}) -> http_transport:close(SocketType, Socket). activate_request_timeout( - #state{request = #request{timer = undefined} = Request} = State) -> + #state{request = #request{timer = OldRef} = Request} = State) -> Timeout = (Request#request.settings)#http_options.timeout, case Timeout of infinity -> @@ -1232,17 +1232,21 @@ activate_request_timeout( _ -> ReqId = Request#request.id, Msg = {timeout, ReqId}, + case OldRef of + undefined -> + ok; + _ -> + %% Timer is already running! This is the case for a redirect or retry + %% We need to restart the timer because the handler pid has changed + cancel_timer(OldRef, Msg) + end, Ref = erlang:send_after(Timeout, self(), Msg), Request2 = Request#request{timer = Ref}, ReqTimers = [{Request#request.id, Ref} | (State#state.timers)#timers.request_timers], Timers = #timers{request_timers = ReqTimers}, State#state{request = Request2, timers = Timers} - end; - -%% Timer is already running! This is the case for a redirect or retry -activate_request_timeout(State) -> - State. + end. activate_queue_timeout(infinity, State) -> State; |