# Proxy\_next\_upstream, only "connect" timeout?

**URL:** <https://www.ruby-forum.com/t/proxy-next-upstream-only-connect-timeout/220573>\
**Category:** NGINX\
**Created:** [June 13, 2012, 2:10pm UTC](https://www.ruby-forum.com/t/proxy-next-upstream-only-connect-timeout/220573 "2012-06-13T14:10:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [June 13, 2012, 2:10pm UTC](https://www.ruby-forum.com/t/proxy-next-upstream-only-connect-timeout/220573/1 "2012-06-13T14:10:02Z")

</div>

hi,

is there any way to tell nginx to fallback to the next upstream in  
case of timeout,  
but only if the timeout occured during connection (for example because  
the upstream’s backlog is full),  
and not when the upstream is already processing the request? basically  
the case specified by the proxy\_connect\_timeout.

it seems if i do:  
“proxy\_next\_upstream timeout”, then this can happen:

1. nginx sends the request to upstream1
2. upstream1 begins processing the request, stores data in the db, etc
3. while upstream1 creates the response, the timeout happens, and  
nginx sends the request to upstream2
4. upstream2 begins processing the request, stores data in the db, etc

at this point the request was processed twice, data were written in  
the database twice etc. i would like to avoid it.

but, on the other hand, if i say “proxy\_next\_upstream off”, then this  
can happen:

1. nginx sends the request to upstream1
2. upstream1’s socket-backlog is full, so nginx returns a http504 to  
the user, even if there is upstream2, that theoretically could have  
served the request.

any ideas how to handle this situation?

thanks,  
gabor
