<div dir="ltr"><div class="gmail_default" style="font-family:courier new,monospace">My current guess: This is a bug in how the socket is set up or one of the underlying libraries.</div><div class="gmail_default" style="font-family:courier new,monospace">

<br></div><div class="gmail_default" style="font-family:courier new,monospace">Using the stream debug hooks indicates the failure is due to "readLine" returning an empty line when parsing the request header. I cannot tell if an empty line is returned due to an actual 0 byte return from read/recv or some processing of the read data. Still, this would indicate the HTTP library considers the request to be malformed.</div>

<div class="gmail_default" style="font-family:courier new,monospace"><br></div><div class="gmail_default" style="font-family:courier new,monospace">The question is then: Are the requests from JMeter malformed?</div><div class="gmail_default" style="font-family:courier new,monospace">

<br></div><div class="gmail_default" style="font-family:courier new,monospace">A wireshark capture was performed of the JMeter test traffic. This wireshark data indicated 5000 HTTP requests were made. Which is what JMeter produced. All 5000 of these requests were byte identical. This capture did not affect the test results: A similar number of requests failed.</div>

<div class="gmail_default" style="font-family:courier new,monospace"><br></div><div class="gmail_default" style="font-family:courier new,monospace">I tried to instrument the read/recv calls using dtrace. This indicated read, and not recv, was used when reading from teh socket. I was unable to determine anything else tho. Probably a better idea to instrument HTTP library a bit more.</div>

<div class="gmail_default" style="font-family:courier new,monospace"><br></div><div class="gmail_default" style="font-family:courier new,monospace">Cheers,</div><div class="gmail_default" style="font-family:courier new,monospace">

Corey</div><div class="gmail_default" style="font-family:courier new,monospace"><br></div><div class="gmail_default" style="font-family:courier new,monospace"><br></div></div><div class="gmail_extra"><br clear="all"><div>

<div dir="ltr"><font face="courier new, monospace">-Corey O'Connor<br><a href="mailto:coreyoconnor@gmail.com" target="_blank">coreyoconnor@gmail.com</a><br><a href="http://corebotllc.com/" target="_blank">http://corebotllc.com/</a></font></div>

</div>
<br><br><div class="gmail_quote">On Tue, Nov 5, 2013 at 6:10 PM, Corey O'Connor <span dir="ltr"><<a href="mailto:coreyoconnor@gmail.com" target="_blank">coreyoconnor@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div dir="ltr"><div class="gmail_default" style="font-family:courier new,monospace">I've updated the code to handle persistent connections. As best I can figure anyways..</div><div class="gmail_default" style="font-family:courier new,monospace">


Unfortunately this does not resolve the issue. The server still reports the connection being closed before the full response is read.</div><div class="gmail_default" style="font-family:courier new,monospace"><br></div><div class="gmail_default" style="font-family:courier new,monospace">


The test is done via JMeter. See the perf_test.jmx file. I've confirmed JMeter is include "connection: close" headers in all requests. Which means the persistent connection code is not even being exercised. From instrumenting the code I can confirm this is the case: All requests include "connection: close" and the client never performs a second request using the same stream.</div>


<div class="gmail_default" style="font-family:courier new,monospace"><br></div><div class="gmail_default" style="font-family:courier new,monospace">An additional data point: The same test when run with 1 capability (EG: +RTS -N1) does *not* fail. There are no connection close errors. Only when running with multiple capabilities does the test fail.</div>


<div class="gmail_default" style="font-family:courier new,monospace"><br></div><div class="gmail_default" style="font-family:courier new,monospace">Cheers,</div><div class="gmail_default" style="font-family:courier new,monospace">


Corey</div><div class="gmail_default" style="font-family:courier new,monospace"><br></div></div><div class="gmail_extra"><div class="im"><br clear="all"><div><div dir="ltr"><font face="courier new, monospace">-Corey O'Connor<br>

<a href="mailto:coreyoconnor@gmail.com" target="_blank">coreyoconnor@gmail.com</a><br>
<a href="http://corebotllc.com/" target="_blank">http://corebotllc.com/</a></font></div></div>
<br><br></div><div><div class="h5"><div class="gmail_quote">On Tue, Oct 22, 2013 at 4:54 PM, Corey O'Connor <span dir="ltr"><<a href="mailto:coreyoconnor@gmail.com" target="_blank">coreyoconnor@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div><div><div class="gmail_default" style="font-family:'courier new',monospace"><span style="font-family:arial">On Mon, Oct 21, 2013 at 7:28 PM, Joey Adams </span><span dir="ltr" style="font-family:arial"><<a href="mailto:joeyadams3.14159@gmail.com" target="_blank">joeyadams3.14159@gmail.com</a>></span><span style="font-family:arial"> wrote:</span><br>



</div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


<div dir="ltr">
<div>On Mon, Oct 21, 2013 at 5:15 PM, Corey O'Connor <span dir="ltr"><<a href="mailto:coreyoconnor@gmail.com" target="_blank">coreyoconnor@gmail.com</a>></span> wrote:<br></div><div class="gmail_extra">
<div class="gmail_quote"><div>


<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div style="font-family:'courier new',monospace">





Curiously: If the Network.HTTP.close is removed the server does not fail, but some requests takes several seconds to process. I presume the ordering of effects is then correct, but without the explicit close the close occurs only a GC time.<br>





</div>
</div></blockquote><div><br></div></div><div>The client may be trying to reuse the connection; see <a href="http://en.wikipedia.org/wiki/HTTP_persistent_connection" target="_blank">http://en.wikipedia.org/wiki/HTTP_persistent_connection</a>.  This seems consistent with your results:</div>






<div><br></div><div> * With the close call: connection is closed right after client sends a second request, so client whines.</div><div> * Without the close call: client waits around for a response, then gives up and establishes another connection.</div>






<div><br></div><div>To confirm, add another <span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:12px;line-height:18px;white-space:pre-wrap">receiveHTTP</span> call <span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:12px;line-height:18px;white-space:pre-wrap">client_interact and see if it returns another Request.</span></div>



</div></div></div></blockquote><div><br></div></div></div><div><div class="gmail_default" style="font-family:'courier new',monospace">​Thanks!​ I'll try your test and see if anything changes.</div><div class="gmail_default" style="font-family:'courier new',monospace">



<br></div><div class="gmail_default" style="font-family:'courier new',monospace">Though I thought the code accounted for this: A connection close header is added to each response. Which I thought would cause the client to close the connection.​​ I could be totally wrong tho. There could be some additional aspect of HTTP connections I do not understand.</div>



</div><div class="gmail_default" style="font-family:'courier new',monospace"><br></div><div class="gmail_default" style="font-family:'courier new',monospace">Properly supporting persistent connections should be pretty easy. There is another Network.HTTP server package that does this: <a href="http://hackage.haskell.org/package/http-server-1/docs/Network-HTTP-Server.html" target="_blank">http://hackage.haskell.org/package/http-server-1/docs/Network-HTTP-Server.html</a></div>



<div class="gmail_default" style="font-family:'courier new',monospace"><br></div><div class="gmail_default" style="font-family:'courier new',monospace">So I'll give that a shot and report back.</div><div class="gmail_default" style="font-family:'courier new',monospace">



<br></div><div class="gmail_default" style="font-family:'courier new',monospace">Thanks!</div><span><font color="#888888"><div class="gmail_default" style="font-family:'courier new',monospace">
Corey</div></font></span></div><br></div></div>
</blockquote></div><br></div></div></div>
</blockquote></div><br></div>