<div dir="ltr">Thanks Alex, this is very helpful.<div><br></div><div>Another interesting fact is that I can't reproduce this issue if squid has no other traffic except my testing requests. But it's easy to reproduce when server has other traffic.</div><div><br></div><div>The problem is that with other traffic I can't provide the whole log file with debug ALL,7 enabled because it has other requests.</div><div><br></div><div>So I tried to select only parts related to my test request (this is ALL,7):</div><div><br></div><div><a href="https://www.dropbox.com/s/udzeipeerf5o38t/squid_retry_logs.tgz?dl=1">https://www.dropbox.com/s/udzeipeerf5o38t/squid_retry_logs.tgz?dl=1</a></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 28, 2017 at 7:32 AM, Alex Rousskov <span dir="ltr"><<a href="mailto:rousskov@measurement-factory.com" target="_blank">rousskov@measurement-factory.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 11/27/2017 05:19 PM, Ivan Larionov wrote:<br>
<br>
> I see retries only when squid config has 2 parents. If I comment out<br>
> everything related to "newproxy" I can't reproduce this behavior anymore.<br>
<br>
</span>The posted logs are not detailed enough to confirm or deny that IMO, but<br>
I suspect that you are dealing with at least one bug.<br>
<span class=""><br>
<br>
> <a href="https://wiki.squid-cache.org/SquidFaq/InnerWorkings#When_does_Squid_re-forward_a_client_request.3F" rel="noreferrer" target="_blank">https://wiki.squid-cache.org/<wbr>SquidFaq/InnerWorkings#When_<wbr>does_Squid_re-forward_a_<wbr>client_request.3F</a><br>
><br>
>> Squid does not try to re-forward a request if at least one of the following conditions is true:<br>
>><br>
>> The number of forwarding attempts exceeded forward_max_tries. For<br>
>> example, if you set forward_max_tries to 1 (one), then no requests<br>
>> will be re-forwarded.<br>
<br>
<br>
</span>AFAICT, there is an off-by-one bug in Squid that violates the above:<br>
<br>
>     if (n_tries > Config.forward_max_tries)<br>
>         return false;<br>
<br>
The n_tries counter is incremented before Squid makes a request<br>
forwarding attempt. With n_tries and Config.forward_max_tries both set<br>
to 1, the quoted FwdState::checkRetry() code will not prevent<br>
re-forwarding. There is a similar problem in FwdState::reforward(). This<br>
reasoning needs confirmation/testing.<br>
<br>
Please note that simply changing the ">" operator to ">=" may break<br>
other things in a difficult-to-detect-by-simple-<wbr>tests ways. The correct<br>
fix may be more complex than it looks and may involve making policy<br>
decisions regarding forward_max_tries meaning. The best fix would remove<br>
checkRetry() and reforward() duplication. This code is difficult to work<br>
with; many related code names are misleading.<br>
<span class=""><br>
<br>
>> Squid has no alternative destinations to try. Please note that<br>
>> alternative destinations may include multiple next hop IP addresses<br>
>> and multiple peers.<br>
<br>
</span>The fact that Squid sends two requests to the same peer with only one<br>
peer address selected suggests that Squid is retrying a failed<br>
persistent connection rather than re-forwarding after receiving a bad<br>
response. Again, the logs are not detailed enough to distinguish the two<br>
cases. I can only see that a single peer/destination address was<br>
selected (not two), which is correct/expected behavior. I cannot see<br>
what happened next with sufficient detail.<br>
<br>
Going forward, you have several options, including:<br>
<br>
A. Post a link to compressed ALL,7+ logs to confirm bug(s).<br>
B. Fix the broken condition(s) in FwdState. See above.<br>
<br>
HTH,<br>
<br>
Alex.<br>
<span class=""><br>
<br>
> 2017/11/27 15:53:40.542| 5,2| TcpAcceptor.cc(220) doAccept: New connection on FD 15<br>
> 2017/11/27 15:53:40.542| 5,2| TcpAcceptor.cc(295) acceptNext: connection<br>
</span>> on local=<a href="http://0.0.0.0:3128" rel="noreferrer" target="_blank">0.0.0.0:3128</a> <<a href="http://0.0.0.0:3128" rel="noreferrer" target="_blank">http://0.0.0.0:3128</a>> remote=[::] FD 15 flags=9<br>
<span class="">> 2017/11/27 15:53:40.543| 11,2| client_side.cc(2372) parseHttpRequest:<br>
</span>> HTTP Client local=<a href="http://127.0.0.1:3128" rel="noreferrer" target="_blank">127.0.0.1:3128</a> <<a href="http://127.0.0.1:3128" rel="noreferrer" target="_blank">http://127.0.0.1:3128</a>><br>
> remote=<a href="http://127.0.0.1:53798" rel="noreferrer" target="_blank">127.0.0.1:53798</a> <<a href="http://127.0.0.1:53798" rel="noreferrer" target="_blank">http://127.0.0.1:53798</a>> FD 45 flags=1<br>
<span class="">> 2017/11/27 15:53:40.543| 11,2| client_side.cc(2373) parseHttpRequest:<br>
> HTTP Client REQUEST:<br>
> ---------<br>
> GET <a href="http://HOST:12345/" rel="noreferrer" target="_blank">http://HOST:12345/</a> HTTP/1.1<br>
> Host: HOST:12345<br>
> User-Agent: curl/7.51.0<br>
> Accept: */*<br>
> Proxy-Connection: Keep-Alive<br>
><br>
><br>
> ----------<br>
> 2017/11/27 15:53:40.543| 85,2| client_side_request.cc(745)<br>
> clientAccessCheckDone: The request GET <a href="http://HOST:12345/" rel="noreferrer" target="_blank">http://HOST:12345/</a> is ALLOWED;<br>
> last ACL checked: localhost<br>
> 2017/11/27 15:53:40.543| 85,2| client_side_request.cc(721)<br>
> clientAccessCheck2: No adapted_http_access configuration. default: ALLOW<br>
> 2017/11/27 15:53:40.543| 85,2| client_side_request.cc(745)<br>
> clientAccessCheckDone: The request GET <a href="http://HOST:12345/" rel="noreferrer" target="_blank">http://HOST:12345/</a> is ALLOWED;<br>
> last ACL checked: localhost<br>
> 2017/11/27 15:53:40.543| 17,2| FwdState.cc(133) FwdState: Forwarding<br>
</span>> client request local=<a href="http://127.0.0.1:3128" rel="noreferrer" target="_blank">127.0.0.1:3128</a> <<a href="http://127.0.0.1:3128" rel="noreferrer" target="_blank">http://127.0.0.1:3128</a>><br>
> remote=<a href="http://127.0.0.1:53798" rel="noreferrer" target="_blank">127.0.0.1:53798</a> <<a href="http://127.0.0.1:53798" rel="noreferrer" target="_blank">http://127.0.0.1:53798</a>> FD 45 flags=1,<br>
<span class="">> url=<a href="http://HOST:12345/" rel="noreferrer" target="_blank">http://HOST:12345/</a><br>
> 2017/11/27 15:53:40.543| 44,2| peer_select.cc(258) peerSelectDnsPaths:<br>
> Find IP destination for: <a href="http://HOST:12345/" rel="noreferrer" target="_blank">http://HOST:12345/</a>' via 127.0.0.1<br>
> 2017/11/27 15:53:40.543| 44,2| peer_select.cc(280) peerSelectDnsPaths:<br>
> Found sources for '<a href="http://HOST:12345/" rel="noreferrer" target="_blank">http://HOST:12345/</a>'<br>
> 2017/11/27 15:53:40.543| 44,2| peer_select.cc(281) peerSelectDnsPaths: <br>
>  always_direct = DENIED<br>
> 2017/11/27 15:53:40.543| 44,2| peer_select.cc(282) peerSelectDnsPaths: <br>
>   never_direct = ALLOWED<br>
> 2017/11/27 15:53:40.543| 44,2| peer_select.cc(292) peerSelectDnsPaths: <br>
>     cache_peer = local=127.0.0.3 remote=<a href="http://127.0.0.1:18070" rel="noreferrer" target="_blank">127.0.0.1:18070</a><br>
</span>> <<a href="http://127.0.0.1:18070" rel="noreferrer" target="_blank">http://127.0.0.1:18070</a>> flags=1<br>
<span class="">> 2017/11/27 15:53:40.543| 44,2| peer_select.cc(295) peerSelectDnsPaths: <br>
>       timedout = 0<br>
> 2017/11/27 15:53:40.543| 11,2| http.cc(2229) sendRequest: HTTP Server<br>
</span>> local=<a href="http://127.0.0.3:57091" rel="noreferrer" target="_blank">127.0.0.3:57091</a> <<a href="http://127.0.0.3:57091" rel="noreferrer" target="_blank">http://127.0.0.3:57091</a>> remote=<a href="http://127.0.0.1:18070" rel="noreferrer" target="_blank">127.0.0.1:18070</a><br>
> <<a href="http://127.0.0.1:18070" rel="noreferrer" target="_blank">http://127.0.0.1:18070</a>> FD 40 flags=1<br>
<span class="">> 2017/11/27 15:53:40.543| 11,2| http.cc(2230) sendRequest: HTTP Server<br>
> REQUEST:<br>
> ---------<br>
> GET <a href="http://HOST:12345/" rel="noreferrer" target="_blank">http://HOST:12345/</a> HTTP/1.1<br>
> User-Agent: curl/7.51.0<br>
> Accept: */*<br>
> Host: HOST:12345<br>
> Cache-Control: max-age=259200<br>
> Connection: keep-alive<br>
><br>
><br>
> ----------<br>
><br>
> [SKIPPED 40 seconds until parent closes TCP connection with FIN,ACK]<br>
><br>
> 2017/11/27 15:54:20.627| 11,2| http.cc(1299) continueAfterParsingHeader:<br>
> WARNING: HTTP: Invalid Response: No object data received for<br>
> <a href="http://HOST:12345/" rel="noreferrer" target="_blank">http://HOST:12345/</a> AKA HOST/<br>
> 2017/11/27 15:54:20.627| 17,2| FwdState.cc(655)<br>
> handleUnregisteredServerEnd: self=0x3e31838*2 err=0x409b338<br>
> <a href="http://HOST:12345/" rel="noreferrer" target="_blank">http://HOST:12345/</a><br>
> 2017/11/27 15:54:20.627| 11,2| http.cc(2229) sendRequest: HTTP Server<br>
</span>> local=<a href="http://127.0.0.3:41355" rel="noreferrer" target="_blank">127.0.0.3:41355</a> <<a href="http://127.0.0.3:41355" rel="noreferrer" target="_blank">http://127.0.0.3:41355</a>> remote=<a href="http://127.0.0.1:18070" rel="noreferrer" target="_blank">127.0.0.1:18070</a><br>
> <<a href="http://127.0.0.1:18070" rel="noreferrer" target="_blank">http://127.0.0.1:18070</a>> FD 40 flags=1<br>
<span class="">> 2017/11/27 15:54:20.627| 11,2| http.cc(2230) sendRequest: HTTP Server<br>
> REQUEST:<br>
> ---------<br>
> GET <a href="http://HOST:12345/" rel="noreferrer" target="_blank">http://HOST:12345/</a> HTTP/1.1<br>
> User-Agent: curl/7.51.0<br>
> Accept: */*<br>
> Host: HOST:12345<br>
> Cache-Control: max-age=259200<br>
> Connection: keep-alive<br>
><br>
><br>
> ----------<br>
><br>
> [SKIPPED 40 seconds again until parent closes TCP connection with FIN,ACK]<br>
><br>
> 2017/11/27 15:55:00.728| ctx: enter level  0: '<a href="http://HOST:12345/" rel="noreferrer" target="_blank">http://HOST:12345/</a>'<br>
> 2017/11/27 15:55:00.728| 11,2| http.cc(719) processReplyHeader: HTTP<br>
</span>> Server local=<a href="http://127.0.0.3:41355" rel="noreferrer" target="_blank">127.0.0.3:41355</a> <<a href="http://127.0.0.3:41355" rel="noreferrer" target="_blank">http://127.0.0.3:41355</a>><br>
> remote=<a href="http://127.0.0.1:18070" rel="noreferrer" target="_blank">127.0.0.1:18070</a> <<a href="http://127.0.0.1:18070" rel="noreferrer" target="_blank">http://127.0.0.1:18070</a>> FD 40 flags=1<br>
<span class="">> 2017/11/27 15:55:00.728| 11,2| http.cc(720) processReplyHeader: HTTP<br>
> Server REPLY:<br>
> ---------<br>
> HTTP/1.0 502 Bad Gateway<br>
> Cache-Control: no-cache<br>
> Connection: close<br>
> Content-Type: text/html<br>
><br>
> <html><body><h1>502 Bad Gateway</h1><br>
> The server returned an invalid or incomplete response.<br>
> </body></html><br>
><br>
> ----------<br>
> 2017/11/27 15:55:00.728| ctx: exit level  0<br>
> 2017/11/27 15:55:00.728| 20,2| store.cc(996) checkCachable:<br>
> StoreEntry::checkCachable: NO: not cachable<br>
> 2017/11/27 15:55:00.728| 20,2| store.cc(996) checkCachable:<br>
> StoreEntry::checkCachable: NO: not cachable<br>
> 2017/11/27 15:55:00.728| 88,2| client_side_reply.cc(2073)<br>
> processReplyAccessResult: The reply for GET <a href="http://HOST:12345/" rel="noreferrer" target="_blank">http://HOST:12345/</a> is<br>
> ALLOWED, because it matched (access_log stdio:/var/log/squid/access.<wbr>log<br>
> line)<br>
> 2017/11/27 15:55:00.728| 11,2| client_side.cc(1409) sendStartOfMessage:<br>
</span>> HTTP Client local=<a href="http://127.0.0.1:3128" rel="noreferrer" target="_blank">127.0.0.1:3128</a> <<a href="http://127.0.0.1:3128" rel="noreferrer" target="_blank">http://127.0.0.1:3128</a>><br>
> remote=<a href="http://127.0.0.1:53798" rel="noreferrer" target="_blank">127.0.0.1:53798</a> <<a href="http://127.0.0.1:53798" rel="noreferrer" target="_blank">http://127.0.0.1:53798</a>> FD 45 flags=1<br>
<div class="HOEnZb"><div class="h5">> 2017/11/27 15:55:00.728| 11,2| client_side.cc(1410) sendStartOfMessage:<br>
> HTTP Client REPLY:<br>
> ---------<br>
> HTTP/1.1 502 Bad Gateway<br>
> Date: Mon, 27 Nov 2017 23:54:20 GMT<br>
> Cache-Control: no-cache<br>
> Content-Type: text/html<br>
> X-Cache: MISS from ip-172-23-18-130<br>
> X-Cache-Lookup: MISS from ip-172-23-18-130:3128<br>
> Transfer-Encoding: chunked<br>
> Connection: keep-alive<br>
><br>
><br>
> ----------<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">With best regards, Ivan Larionov.</div>
</div>