From 07d1d75d54b188c31aaf40e4353faa079be785b9 Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Thu, 12 Sep 2013 15:54:46 -0400 Subject: [PATCH] Retry requests when the worker has the connection close When a tcp_closed or ssl_closed message is handled while ibrowse is trying to send a request to a worker, ibrowse would incorrectly return a req_timedout message, when, in fact, the request had not even been handled. This patch attempts to avoid that race condition by signalling tcp or ssl closed messages back to ibrowse differently than a normal exit. --- src/ibrowse.erl | 2 ++ src/ibrowse_http_client.erl | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ibrowse.erl b/src/ibrowse.erl index 5364587..42030af 100644 --- a/src/ibrowse.erl +++ b/src/ibrowse.erl @@ -443,6 +443,8 @@ do_send_req(Conn_Pid, Parsed_url, Headers, Method, Body, Options, Timeout) -> {error, sel_conn_closed}; {'EXIT', {normal, _}} -> {error, req_timedout}; + {'EXIT', {connection_closed, _}} -> + {error, sel_conn_closed}; {error, connection_closed} -> {error, sel_conn_closed}; {'EXIT', Reason} -> diff --git a/src/ibrowse_http_client.erl b/src/ibrowse_http_client.erl index a903ac3..fd2c25d 100644 --- a/src/ibrowse_http_client.erl +++ b/src/ibrowse_http_client.erl @@ -215,11 +215,11 @@ handle_info({stream_close, _Req_id}, State) -> handle_info({tcp_closed, _Sock}, State) -> do_trace("TCP connection closed by peer!~n", []), handle_sock_closed(State), - {stop, normal, State}; + {stop, connection_closed, State}; handle_info({ssl_closed, _Sock}, State) -> do_trace("SSL connection closed by peer!~n", []), handle_sock_closed(State), - {stop, normal, State}; + {stop, connection_closed, State}; handle_info({tcp_error, _Sock, Reason}, State) -> do_trace("Error on connection to ~1000.p:~1000.p -> ~1000.p~n",