Welcome! Log In Create A New Profile

Advanced

keepalive connection to fastcgi backend hangs

Nicolas Franck
December 19, 2021 02:58PM
I've created a server setup where nginx acts as
a proxy server for a fastcgi application.
That last application is running on a different server on port 9000.
It is spawn with spawn-fcgi.
Recently I have found out that nginx
closes the connection after every request.

In order to make nginx keep the tcp connections alive,
I've added the following settings:

* proxy_socket_keepalive on
* proxy_http_version 1.1;
* proxy_set_header Connection "";
* fastcgi_keep_conn on;
* added an upstream "fgi":

upstream fcgi {
keepalive 10;
server myhost:9000;
}

* added a location block (only snippet given):

location /fcgi {
fastcgi_pass_request_headers on;
fastcgi_pass fcgi;
fastcgi_keep_conn on;
}

What I see: after a couple of requests nginx "hangs" when I visit path "/fcgi".

This disappears when

* I remove the setting "keepalive" from the upstream (but that disables keepalive altogether)
* bind the fcgi application to a unix socket, and let nginx bind to that. But that requires nginx and the fcgi to be on the same server.
* reduce the number of nginx workers to exactly 1. Not sure why that works.
* I spawn the application with tool "supervisord" (a fcgi process manager written in python)

Does anyone know what is happening here?
Fcgi has little documentation on the web..

Example of an application: fcgi_example.cpp

#include <iostream>
#include <fcgio.h>
#include <fcgiapp.h>

void handle_request(FCGX_Request& request){
fcgi_streambuf cout_fcgi_streambuf(request.out);
std::ostream os{&cout_fcgi_streambuf};

os << "HTTP/1.1 200 OK\r\n"
<< "Content-type: text/plain\r\n\r\n"
<< "Hello!\r\n";
}

int main(){
FCGX_Request request;
FCGX_Init();
FCGX_InitRequest(&request, 0, 0);
while (FCGX_Accept_r(&request) == 0) {
handle_request(request);
}
}

Build: g++ -std=c++11 -lfcgi -lfcgi++ -o fcgi_example fcgi_example.cpp

Spawn: spawn-fcgi -f /path/to/fcgi_example.cpp -p 9000




_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

keepalive connection to fastcgi backend hangs

Nicolas Franck December 19, 2021 02:58PM

Re: keepalive connection to fastcgi backend hangs

Maxim Dounin December 20, 2021 09:12AM

Re: keepalive connection to fastcgi backend hangs

Nicolas Franck December 20, 2021 11:02AM

Re: keepalive connection to fastcgi backend hangs

Maxim Dounin December 20, 2021 02:36PM

Re: keepalive connection to fastcgi backend hangs

Nicolas Franck December 20, 2021 03:56PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 124
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready