<div dir="ltr">
<p class=""><span class=""><font face="monospace, monospace">In <a href="http://erlang.org/pipermail/erlang-questions/2014-February/077788.html"><span class="">http://erlang.org/pipermail/erlang-questions/2014-February/077788.html</span></a> and elsewhere, users </font></span><span style="font-family:monospace,monospace">observed that httpc would occasionally encounter `{error,socket_closed_remotely}` when querying a </span><span style="font-family:monospace,monospace">web service of some sort. The workaround was to use https 1.0, as opposed to 1.1, which is somewhat </span><span style="font-family:monospace,monospace">of an unsatisfying resolution.</span></p>
<p class=""><span style="font-family:monospace,monospace">I have this (I believe) same problem and have tried to create a minimal example that</span><span style="font-family:monospace,monospace"> </span><span style="font-family:monospace,monospace">reproduces the issue using a public url to post a simple JSON body (my 'real' code posts data to a </span><font face="monospace, monospace"><span class="">ChicagoBoss server).</span> I am hoping that someone more qualified than I can take this bit of “research” </font><span style="font-family:monospace,monospace">and maybe figure out this bug? Alternatively, if someone can nudge me in the right direction, </span><span style="font-family:monospace,monospace">I </span><b style="font-family:monospace,monospace">might</b><span style="font-family:monospace,monospace"> be able to take this further…</span></p><p class=""><font face="monospace, monospace">My code is as follows:</font></p><p class=""><font face="monospace, monospace"><br></font></p>
<p class=""><span class=""><font face="monospace, monospace">-module(httpc_bug).</font></span></p>
<p class=""><span class=""><font face="monospace, monospace">-export([test/0]).</font></span></p>
<p class=""><font face="monospace, monospace"><span class=""></span><br></font></p>
<p class=""><span class=""><font face="monospace, monospace">test()-></font></span></p>
<p class=""><font face="monospace, monospace"><span class=""> httpc:set_options([{max_keep_alive_length, 0},</span></font></p><p class=""><font face="monospace, monospace"> {max_pipeline_length, 0}, </font></p><p class=""><font face="monospace, monospace"> {max_sessions, 0}]),</font></p>
<p class=""><span class=""><font face="monospace, monospace"> test_put(0).</font></span></p>
<p class=""><font face="monospace, monospace"><span class=""></span><br></font></p>
<p class=""><span class=""><font face="monospace, monospace">test_put(N) -></font></span></p>
<p class=""><span class=""><font face="monospace, monospace"> Url = "<a href="https://posttestserver.com/post.php">https://posttestserver.com/post.php</a>",</font></span></p>
<p class=""><span class=""><font face="monospace, monospace"> ContentType= "application/json",</font></span></p>
<p class=""><span class=""><font face="monospace, monospace"> Body = <<"{\"type\":\"body type\",\"value\":2}">>,</font></span></p>
<p class=""><span class=""><font face="monospace, monospace"> Header = [],</font></span></p>
<p class=""><span class=""><font face="monospace, monospace"> HttpOptions = [],</font></span></p>
<p class=""><span class=""><font face="monospace, monospace"> Options = [],</font></span></p>
<p class=""><font face="monospace, monospace"><span class=""> </span> case httpc:request(post, {Url, Header, ContentType, Body}, HttpOptions, Options) of</font></p>
<p class=""><span class=""><font face="monospace, monospace"><span class=""></span> {ok, {{_V, _Cd, _R}, _RespHeader, B }} -> </font></span></p>
<p class=""><span class=""><font face="monospace, monospace"> io:format("~p[~p]:~p~n”, [self(), N, B]),</font></span></p>
<p class=""><span class=""><font face="monospace, monospace"><span class=""></span> test_put(N+1);</font></span></p>
<p class=""><span class=""><font face="monospace, monospace"><span class=""></span> {error, Reason} -></font></span></p>
<p class=""><span class=""><font face="monospace, monospace"> io:format("~p: died after ~p iterations with: ~p. ~n.", </font></span></p><p class=""><span class=""><font face="monospace, monospace"> [self(), N, Reason])</font></span></p>
<p class=""><span class=""><font face="monospace, monospace"> end.</font></span></p>
<p class=""><font face="monospace, monospace"><span class=""></span><br></font></p><p class=""><font face="monospace, monospace">The problem manifests itself regardless of the options (httpc:setoptions/1) used - or not used. I chose the ones that I did to try to eliminate code-paths involved.</font></p>
<p class=""><span class=""><font face="monospace, monospace">A typical run looks like this:</font></span></p>
<p class=""><font face="monospace, monospace"><span class=""></span><br></font></p>
<p class=""><span class=""><font face="monospace, monospace">Erlang/OTP 17 [erts-6.2] [source-aaaefb3] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]</font></span></p>
<p class=""><font face="monospace, monospace"><span class=""></span><br></font></p>
<p class=""><span class=""><font face="monospace, monospace">Eshell V6.2 (abort with ^G)</font></span></p>
<p class=""><span class=""><font face="monospace, monospace">1> inets:start().</font></span></p>
<p class=""><span class=""><font face="monospace, monospace">ok</font></span></p>
<p class=""><span class=""><font face="monospace, monospace">2> ssl:start().</font></span></p>
<p class=""><span class=""><font face="monospace, monospace">ok</font></span></p>
<p class=""><span class=""><font face="monospace, monospace">3> code:load_file(httpc_bug).</font></span></p>
<p class=""><span class=""><font face="monospace, monospace">{module,httpc_bug}</font></span></p>
<p class=""><span class=""><font face="monospace, monospace">4> httpc_bug:test(1).</font></span></p>
<p class=""><span class=""><font face="monospace, monospace">[<0.15201.0>]</font></span></p>
<p class=""><span class=""><font face="monospace, monospace"><0.15201.0>[0]:"Successfully dumped 0 post variables.\nView it at <a href="http://www.posttestserver.com/data/2015/03/13/19.21.45157935823\nPost">http://www.posttestserver.com/data/2015/03/13/19.21.45157935823\nPost</a> body was 30 chars long."</font></span></p>
<p class=""><span class=""><font face="monospace, monospace"><0.15201.0>[1]:"Successfully dumped 0 post variables.\nView it at <a href="http://www.posttestserver.com/data/2015/03/13/19.21.451784952425\nPost">http://www.posttestserver.com/data/2015/03/13/19.21.451784952425\nPost</a> body was 30 chars long."</font></span></p>
<p class=""><span class=""><font face="monospace, monospace">. SNIP</font></span></p>
<p class=""><span class=""><font face="monospace, monospace"><0.15201.0>: died after 102 iterations with: socket_closed_remotely.</font></span></p>
<p class=""><font face="monospace, monospace"><span class=""></span><br></font></p>
<p class=""><span class=""><font face="monospace, monospace">I just did five runs, four died in under 410 iterations, and the fifth took 809 iterations.</font></span></p>
<p class=""><font face="monospace, monospace"><span class=""></span><br></font></p>
<p class=""><span class=""><font face="monospace, monospace">By examining the contents of the http_manager__session_db </font></span><span style="font-family:monospace,monospace">before each call to the httpc:request, I am pretty sure that the flow </span><span style="font-family:monospace,monospace">goes:</span></p>
<p class=""><font face="monospace, monospace"><span class=""></span><br></font></p>
<p class=""><span class=""><font face="monospace, monospace">httpc_manager.erl line 759 — within a handle_request clause</font></span></p>
<p class=""><span class=""><font face="monospace, monospace">handle_request(Request, State = #state{options = Options}) -></font></span></p>
<p class=""><span style="font-family:monospace,monospace"> NewRequest = handle_cookies(generate_request_id(Request), State),</span><br></p>
<p class=""><span class=""><font face="monospace, monospace"> SessionType = session_type(Options),</font></span></p>
<p class=""><span class=""><font face="monospace, monospace"> case select_session(Request#request.method,</font></span></p>
<p class=""><span class=""><font face="monospace, monospace"><span class=""></span><span class=""></span><span class=""></span> Request#request.address,</font></span></p>
<p class=""><span class=""><font face="monospace, monospace"><span class=""></span><span class=""></span><span class=""></span> Request#request.scheme, SessionType, State) of</font></span></p>
<p class=""><span class=""><font face="monospace, monospace"><span class=""></span> {ok, HandlerPid} -></font></span></p>
<p class=""><span class=""><font face="monospace, monospace"> <b>pipeline_or_keep_alive(NewRequest, HandlerPid, State);</b> </font></span></p><p class=""><span class=""><font face="monospace, monospace"> . SNIP</font></span></p>
<p class=""><span class=""><font face="monospace, monospace"> </font></span></p>
<p class=""><span class=""><font face="monospace, monospace">To </font></span></p>
<p class=""><span class=""><font face="monospace, monospace">httpc_handler.erl line 323 — within a handle_call where keep_alive requests are</font></span></p>
<p class=""><span class=""><font face="monospace, monospace">handled.</font></span></p>
<p class=""><font face="monospace, monospace"><span class=""></span><br></font></p>
<p class=""><span class=""><font face="monospace, monospace">I don’t have the sophistication to take this any further. Is this enough information to </font></span><span style="font-family:monospace,monospace">enable a more qualified individual to pursue this issue.</span></p>
<p class=""><font face="monospace, monospace"><span class=""></span><br></font></p>
<p class=""><span class=""><font face="monospace, monospace">Thoughts much appreciated.</font></span></p>
<p class=""><font face="monospace, monospace"><span class=""></span><br></font></p>
<p class=""><span class=""><font face="monospace, monospace">JR0</font></span></p></div>