Upstream keepalive and fastcgi_next_upstream

vizl nginx-forum на forum.nginx.org
Вт Авг 30 10:57:12 UTC 2016


Hello I notice strange behavior with keepalive and upstream module.

I've backend PHP-FPM with setting configuration 

request_terminate_timeout = 5s

And nginx config:

upstream phpfpm {
  server unix:/tmp/php-fpm-7.sock max_fails=0 fail_timeout=1s;
  keepalive 8;
}

location ^\*.php$ {
  include fastcgi_params;
  fastcgi_index index.php;
  fastcgi_connect_timeout 1;
  fastcgi_next_upstream error timeout http_503;
  fastcgi_keep_conn on;
  fastcgi_intercept_errors on;
  fastcgi_pass phpfpm; 
}  

Then I write simple PHP script which generate 10sec timeout.
So phpfpm get error when "request_terminate_timeout"  exceeded, and I'm
expecting that Nginx also get error 502
but it try send request to upstream again and again. 
I have such errors in my error log: 

2016/08/30 10:22:34 [error] 92078#0: *558411 upstream prematurely closed
connection while reading response header from upstream, client: 1.2.3.4,
server: my.com, request: "GET /?time_out=10 HTTP/1.1", upstream:
"fastcgi://unix:/tmp/php-fpm-7.sock:", host: "
my.com"
2016/08/30 10:22:39 [error] 92078#0: *558411 upstream prematurely closed
connection while reading response header from upstream, client: 1.2.3.4,
server: my.com, request: "GET /?time_out=10 HTTP/1.1", upstream:
"fastcgi://unix:/tmp/php-fpm-7.sock:", host: "
my.com"
2016/08/30 10:22:40 [error] 92078#0: *558411 upstream prematurely closed
connection while reading response header from upstream, client: 1.2.3.4,
server: my.com, request: "GET /?time_out=10 HTTP/1.1", upstream:
"fastcgi://unix:/tmp/php-fpm-7.sock:", host: "
my.com"
2016/08/30 10:22:42 [error] 92078#0: *558411 upstream prematurely closed
connection while reading response header from upstream, client: 1.2.3.4,
server: my.com, request: "GET /?time_out=10 HTTP/1.1", upstream:
"fastcgi://unix:/tmp/php-fpm-7.sock:", host: "
my.com"


When I disable keepalive directive in upstream determination section

upstream phpfpm {
  server unix:/tmp/php-fpm-7.sock max_fails=0 fail_timeout=1s;
}
 
- I get 502 ~6 sec. It's corresponding my request_terminate_timeout 

My version - nginx/1.8.0

Posted at Nginx Forum: https://forum.nginx.org/read.php?21,269285,269285#msg-269285



Подробная информация о списке рассылки nginx-ru