<div>Hi, Maxim,</div><div><br></div><div>I have removed the above code. It seems work for us and there is no side effect. And we have put it on our busy production boxes for a week.</div><div><br></div><div>This patch could make nginx honor the <span style="background-color:rgb(255,255,255);color:rgb(34,34,34);font-family:arial,sans-serif;font-size:14px">tries and u->conf->next_upstream variable.</span></div>
<div><br></div><div>The patch is here:</div><div><br></div><div>diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c</div><div>index 842b634..0a0dfc3 100644</div><div>--- a/src/http/ngx_http_upstream.c</div>
<div>+++ b/src/http/ngx_http_upstream.c</div><div>@@ -2845,6 +2845,12 @@ ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u,</div><div> "upstream timed out");</div><div> }</div>
<div><br></div><div>+#if 0</div><div> if (u->peer.cached && ft_type == NGX_HTTP_UPSTREAM_FT_ERROR) {</div><div> status = 0;</div><div><br></div><div>@@ -2853,6 +2859,7 @@ ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u,</div>
<div> u->peer.tries++;</div><div><br></div><div> } else {</div><div>+#endif</div><div> switch(ft_type) {</div><div><br></div><div> case NGX_HTTP_UPSTREAM_FT_TIMEOUT:</div><div>@@ -2875,7 +2882,9 @@ ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u,</div>
<div> default:</div><div> status = NGX_HTTP_BAD_GATEWAY;</div><div> }</div><div>+#if 0</div><div> }</div><div>+#endif</div><div><br></div><div> if (r->connection->error) {</div><div>
ngx_http_upstream_finalize_request(r, u,</div><div>~</div><div><br></div><br><div class="gmail_quote">2013/1/14 Ҧΰ±ó <span dir="ltr"><<a href="mailto:yaoweibin@gmail.com" target="_blank">yaoweibin@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The nginx end will close the cacahed connection actively in this next upstream function. I don't know why it should always *retry* other server and don't honor the tries and u->conf->next_upstream variable.<div>
<br></div><div>Thanks.<div><div class="h5"><br><br><div class="gmail_quote">2013/1/14 Maxim Dounin <span dir="ltr"><<a href="mailto:mdounin@mdounin.ru" target="_blank">mdounin@mdounin.ru</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello!<br>
<div><div><br>
On Mon, Jan 14, 2013 at 04:11:20PM +0800, Ҧΰ±ó wrote:<br>
<br>
> Hi, folks,<br>
><br>
> We have found a bug with the keepalive module. When we used the keepalive<br>
> module, the directive proxy_next_upstream seems disabled.<br>
><br>
> We use Nginx as reverse server. Our backend servers simply close connection<br>
> when read some abnormal packets. Nginx will call the function<br>
> ngx_http_upstream_next() and try to use the next server. The ft_type<br>
> is NGX_HTTP_UPSTREAM_FT_ERROR. We want to turn off the try mechanism with<br>
> such packets. Otherwise, it will try all the servers every time. We use<br>
> directive proxy_next_upstream off. If it's not keepalive connection,<br>
> everything is fine. If it's keepalive connection, it will run such code:<br>
><br>
> 2858 if (u->peer.cached && ft_type == NGX_HTTP_UPSTREAM_FT_ERROR) {<br>
> 2859 status = 0;<br>
> 2860<br>
> 2861 /* TODO: inform balancer instead */<br>
> 2862<br>
> 2863 u->peer.tries++;<br>
> 2864<br>
><br>
> The status is cleared to be 0. The below code will never be touched:<br>
><br>
> 2896 if (status) {<br>
> 2897 u->state->status = status;<br>
> 2898<br>
> 2899 if (u->peer.tries == 0 || !(u->conf->next_upstream & ft_type))<br>
> {<br>
><br>
> The variable of tries and u->conf->next_upstream become useless.<br>
><br>
> I don't know why the cached connection should clear the status, Can we just<br>
> remove the code from line 2858 to 2864? Is there any side effect?<br>
<br>
</div></div>Cached connection might be (legitimately) closed by an upstream<br>
server at any time, so the code always retries if sending request<br>
failed.<br>
<span><font color="#888888"><br>
<br>
--<br>
Maxim Dounin<br>
<a href="http://nginx.com/support.html" target="_blank">http://nginx.com/support.html</a><br>
<br>
_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org" target="_blank">nginx@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a></font></span></blockquote></div><br><br clear="all"><div><br></div></div></div><div class="im">
-- <br>Weibin Yao<br>Developer @ Server Platform Team of Taobao
</div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Weibin Yao<br>Developer @ Server Platform Team of Taobao