<div dir="ltr">Hi ya!,<br><br>Thanks for the response.<br><br>I did some additional research.&nbsp; It appears the debate on what to do with half-close clients with regards to HTTP goes back quite a ways.&nbsp; I disagree that it is &quot;strange&quot; to do a TCP half-close, its part and parcel to the protocol itself and situationally, for a client it does make sense to do so.&nbsp;&nbsp; On the other hand, I also agree with you, given the additional background reading I&#39;ve done, its probably just better to avoid it given the ambiguity around doing a half-close in the context of HTTP and varous alludes found in the HTTP RFC(s).<br>
<br>It may or then again it may not be of interest that nginx is somewhat unique in its behavior on how it deals with a half-close compared to other HTTP systems I&#39;ve observed so far.&nbsp; These other systems Apache, IIS, Varnish, lighthttpd, ... first complete the response and then finish the close handshake.&nbsp; nginx is the only system I&#39;ve observed so far which responds with an immediate close (FIN/ACK).<br>
<br>Thanks,<br><br>Ray<br><br><br><div class="gmail_quote">On Sun, Sep 7, 2008 at 9:57 PM, Maxim Dounin <span dir="ltr">&lt;<a href="mailto:mdounin@mdounin.ru">mdounin@mdounin.ru</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hello!<div><div></div><div class="Wj3C7c"><br>
<br>
On Sun, Sep 07, 2008 at 05:15:08PM -0400, Ray Racine wrote:<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
NOT sure this is a nginx problem, but I thought I&#39;d pass it along.<br>
<br>
I have a small custom Scheme HTTP library that uses its FFI to call Linux<br>
socket APIs. &nbsp;In other words, its a home brew implementation. &nbsp;I have used<br>
it to do various HTTP GETs/POSTs for RSS, JSON, etc with success.<br>
<br>
However, when I attempted to do a simple RSS fetch from a site which<br>
responds as &nbsp;Server: nginx/0.6.25, &nbsp;I observed an immediate, and unexpected,<br>
socket close (reset by peer) from nginx. &nbsp; &nbsp;I suspect it might be nginx and<br>
how it handles TCP connections and not the 3rd server application (<br>
<a href="http://www.blippr.com" target="_blank">www.blippr.com</a>). &nbsp;Though it could be the application.<br>
<br>
Here is the sequence of events.<br>
<br>
1) Client connects fine. &nbsp;TCP connect is standard 3-way handshake. &nbsp;SYN,<br>
SYN-ACK, ACK<br>
2) My cliient sends a well-formed HTTP GET request for RSS content.<br>
3) My client library then closes my half of the duplex connection via<br>
&quot;shutdown SHUT_WR&quot;. &nbsp;This means at the TCP level a FIN/ACK is sent to nginx.<br>
(Semantically this means, the client will not be sending any more data.)<br>
4) nginx immediatly responds with a ACK, and then closes the socket without<br>
a response, by sending its own FIN/ACK, to which the client sends an ACK.<br>
In other words a standard 4-way TCP teardown. (Semantically nginx sending<br>
its own FIN/ACK means no more data will be sent.)<br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
>From what little I understand, it appears nginx is incorrectly interrupting<br>
</blockquote>
the &nbsp;SHUT_WR (sends a FIN/ACK) as an end TCP connection. &nbsp;Not as &quot;no more<br>
data will be sent on the write half (from the client) of the duplex TCP<br>
connection.<br>
<br>
However, I think the TCP correct behaviour for nginx should be to respond<br>
the HTTP request. &nbsp;Even though the client intiated SHUT_WR &nbsp;this only<br>
indicates no further data will be sent by the client, to which nginx should<br>
respond with an ACK, but _not_ close the connection until after sending the<br>
HTTP response and then sending its own FIN/ACK.<br>
<br>
The above 1-4 sequence works fine with all other &nbsp;HTTP servers I&#39;ve called<br>
to date.<br>
<br>
I do successfully recieve a response _if_ I do _not_ do a call &quot;shutdown<br>
SHUT_WR&quot; after sending the HTTP GET request, which is the workaround.<br>
<br>
Given my limited knowledge this what I think I&#39;m seeking. &nbsp;It IS very<br>
possible that nginx is not at fault here, but I thougt I&#39;d pass it along.<br>
</blockquote>
<br></div></div>
There is no such thing as half-close in RFC 2616 (Hypertext Transfer Protocol -- HTTP/1.1). &nbsp;The most relevant part I was able to find is from RFC 1945 (Hypertext Transfer Protocol -- HTTP/1.0, 1.3 Overall Operation):<br>

<br>
% &nbsp; &nbsp;Except for experimental applications, current practice requires that<br>
% &nbsp; &nbsp;the connection be established by the client prior to each request and<br>
% &nbsp; &nbsp;closed by the server after sending the response. Both clients and<br>
% &nbsp; &nbsp;servers should be aware that either party may close the connection<br>
% &nbsp; &nbsp;prematurely, due to user action, automated time-out, or program<br>
% &nbsp; &nbsp;failure, and should handle such closing in a predictable fashion. In<br>
% &nbsp; &nbsp;any case, the closing of the connection by either or both parties<br>
% &nbsp; &nbsp;always terminates the current request, regardless of its status.<br>
<br>
Please note: half-close isn&#39;t distinguishable from full close at the other end without sending data. &nbsp;So in your situation server really have two options:<br>
<br>
 &nbsp; 1. Assume client closed connection (&quot;due to user action, automated time-out, or program failure&quot; - e.g. since user clicked &#39;stop&#39; button or clicked a link on a page) and try to minimize performance impact of doing unneeded work.<br>

<br>
 &nbsp; 2. Assume client does something strange with TCP like half-close for some unknown reason, and try to respond anyway.<br>
<br>
By default nginx does 1 if request was proxied to backend and no reply from backend was got yet (and hence nginx has no chance to send data to client for unknown period of time on the one hand, and may save backend from unneded request on the other hand). &nbsp;It may be instructed not to do so by proxy_ignore_client_abort configuration directive.<br>

<br>
The strange thing in your story is that you see &#39;reset by peer&#39;, but I suspect it&#39;s just wording problem and you see normal FIN from nginx side, not RST.<br><font color="#888888">
<br>
Maxim Dounin<br>
</font><br>
p.s. Just don&#39;t use shutdown(SHUT_WR) with http, it&#39;s wrong.<br>
<br>
</blockquote></div><br></div>