Closed alexvazquezfente closed 8 years ago
Hi, thanks for the bug report. The following patch to HEAD of master should fix the problem. The idea behind the try_routing_request function is that ibrowse will retry a request if the connection on which it has chosen to send the request is closed before it can be sent. It will retry if there is enough time left (Timeout value specified), or if the Timeout value is infinity it will be retried 3 times (by default).
$ git diff
diff --git a/src/ibrowse.erl b/src/ibrowse.erl
index b243f36..2876434 100644
--- a/src/ibrowse.erl
+++ b/src/ibrowse.erl
@@ -381,6 +381,13 @@ try_routing_request(Lb_pid, Parsed_url,
{ok, {_Pid_cur_spec_size, _, Conn_Pid}} ->
case do_send_req(Conn_Pid, Parsed_url, Headers,
Method, Body, Options_1, Timeout) of
+ {error, sel_conn_closed} when Timeout == infinity ->
+ try_routing_request(Lb_pid, Parsed_url,
+ Max_sessions,
+ Max_pipeline_size,
+ {SSLOptions, IsSSL},
+ Headers, Method, Body, Options_1,
+ Ori_timeout, Ori_timeout, Req_start_time, Max_attempts, Try_count + 1);
{error, sel_conn_closed} ->
Time_now = os:timestamp(),
Time_taken_so_far = trunc(round(timer:now_diff(Time_now, Req_start_time)/1000)),
By the way, i also don't understand the need to call trunc after round but that is another issue ;)
I'm not sure either, it has been there a long time :-)
Looks good to me.
I don't know how to reproduce the problem in a repeatable way, I think I was very unlucky (actually lucky) to hit the issue. So, I have tested with the help of a mocking library and the fix does solve the issue as expected (by returning {error,retry_later}).
Thank you.
I hit this bug when downloading files using ibrowse v4.2 (although the bug is also present in master). To reproduce it, you just have to specifiy an infinity timeout to ibrowse:send_req/6 and (this is the difficult part to reproduce it without tight control on the server) the server must close the connection.
I was using these parameters:
It can fail with an error badarith if the server closes the connection (at least it is my guess looking at the ibrowse code). This is the stacktrace:
The problems are in the ibrowse:try_routing_request/14 when do_send_req returns {error, sel_conn_closed}. Several invalid calculations calculations are done between the lines 387 and 390 with the Ori_timeout variable which will fail if it has the special value infinity.
I don't provide a patch because i don't exactly know what is the expected behaviour for some of these logic in the infinity timeout case.
By the way, i also don't understand the need to call trunc after round but that is another issue ;)