sockets and file descriptor magic

339 views Asked by At

I have written a FCGI implementation that I use in a Webserver. I wanted to replace a simple setup with lighttpd.

And I found something odd.
When I try to spawn a Python-Flup server and then connect to it, it only works if I use a TCP Socket (My Code). However, in my existing setup with Flup and lighttpd it works also with Unix Domain Sockets.

(In FCGI, the Webserver gives the listening socket to the FCGI server as stdin). So I took a look at Flups code (found it only local and here). It seems that only TCP is handled, so UDS should not work. But with lighttpd it somehow does!

fastcgi.server = (
    "/heiz" =>
    (
       "python-fcgi" =>
       (
        "socket" => "/tmp/fastcgi2.python.sock",
        "bin-path" => "/var/www/heiz/flup.fcgi",
        "check-local" => "disable",
        "max-procs" => 1
       )
    )
)

runs like:

sudo ss -lxp | grep /tmp/fastcgi2.python.sock 
u_str LISTEN 0      1024                    /tmp/fastcgi2.python.sock-0 4378053                                          * 0                                     users:(("flup.fcgi",pid=349092,fd=3),("flup.fcgi",pid=349092,fd=0))

But how? What am I missing?

I think the relevant parts are here and here

Is it due to this magic?

I am confused

1

There are 1 answers

2
gstrauss On

lighttpd opens and binds to the configured listening socket "socket" => "/tmp/fastcgi2.python.sock", whether TCP or UDS, and then makes that listening socket the STDIN_FILENO of your fastcgi backend when you configure "bin-path" => "/var/www/heiz/flup.fcgi"

My understanding is that Flup recognizes that there is a listening socket on STDIN_FILENO (a.k.a. FCGI_LISTENSOCK_FILENO) and simply uses it.