adamdruppe / arsd

This is a collection of modules that I've released over the years. Most of them stand alone, or have just one or two dependencies in here, so you don't have to download this whole repo.
http://arsd-official.dpldocs.info/arsd.html
530 stars 125 forks source link

segmentation fault in cgi.d with fastcgi #443

Closed jtbx closed 3 days ago

jtbx commented 3 days ago

Hi Adam, cgi.d segfaults when compiled with -version=fastcgi:

$ dmd -i -g -version=fastcgi -L-lfcgi test.d
$ ./test
Segmentation fault (core dumped)

Here is a gdb backtrace:

$ gdb test 
Reading symbols from test...
(gdb) run
Starting program: test 

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7fb6a34 in FCGX_PutStr () from /usr/lib64/libfcgi.so.0
(gdb) bt
#0  0x00007ffff7fb6a34 in FCGX_PutStr () from /usr/lib64/libfcgi.so.0
#1  0x00000000004fccd5 in _D4arsd3cgi__T12serveFastCgiS_D4test5helloFCQBqQBo3CgiZvTQoVli5000000ZQCeFSQCvQCt13RequestServerZ9writeFcgiMFAxhZv (__capture=0x7ffff7bb0000, data=...) at arsd/cgi.d:4581
#2  0x00000000004eab7e in _D4arsd3cgi3Cgi5writeMFAxvbbZv (this=0x7ffff7bb1000, maybeAutoClose=true, isAll=false, t=...)
    at arsd/cgi.d:2678
#3  0x00000000004da2c7 in _D4test5helloFC4arsd3cgi3CgiZv (cgi=0x7ffff7bb1000) at ./test.d:12
#4  0x00000000004fcfd5 in _D4arsd3cgi__T12serveFastCgiS_D4test5helloFCQBqQBo3CgiZvTQoVli5000000ZQCeFSQCvQCt13RequestServerZ10doARequestMFZv (__capture=0x7ffff7bb0000) at arsd/cgi.d:4616
#5  0x00000000004fcbef in _D4arsd3cgi__T12serveFastCgiS_D4test5helloFCQBqQBo3CgiZvTQoVli5000000ZQCeFSQCvQCt13RequestServerZv (
    params=...) at arsd/cgi.d:4664
#6  0x00000000004fc8b4 in _D4arsd3cgi13RequestServer__T5serveS_D4test5helloFCQBxQBv3CgiZvTQoVli5000000ZQBwMFZv (this=...)
    at arsd/cgi.d:4166
#7  0x00000000004fc604 in _D4arsd3cgi__T11cgiMainImplS_D4test5helloFCQBpQBn3CgiZvTQoVli5000000ZQCdFAAyaZv (args=...)
    at arsd/cgi.d:4727
#8  0x00000000004da2f0 in _Dmain (args=...) at arsd/cgi.d:3796

The code used is the first example in the cgi.d documentation. Do you know what is happening here?

adamdruppe commented 3 days ago

That's actually kinda expected, fastcgi needs to be run through a special helper thing, otherwise it isn't set up right and has a null pointer when you run it (though you can still test it by running like ./test GET /).

From the docs:

FastCGI is managed from an outside helper, there's one built into Microsoft IIS, Apache httpd, and Lighttpd, and a generic program you can use with nginx called spawn-fcgi.

This is because fastcgi processes are spun up and down on demand so there's some extra meta management stuff in there that is externally fed into it.

What web server are you using?

adamdruppe commented 3 days ago

You can also run it like ./test --port 4432 to listen on a particular port for the web server to connect to your fastcgi instance.

jtbx commented 3 days ago

That's actually kinda expected, fastcgi needs to be run through a special helper thing, otherwise it isn't set up right and has a null pointer when you run it (though you can still test it by running like ./test GET /).

Ah I was trying to set it up similar to a reverse proxy, with the fastcgi process running in the background constantly. Makes sense

From the docs:

FastCGI is managed from an outside helper, there's one built into Microsoft IIS, Apache httpd, and Lighttpd, and a generic program you can use with nginx called spawn-fcgi.

This is because fastcgi processes are spun up and down on demand so there's some extra meta management stuff in there that is externally fed into it.

What web server are you using?

I'm trying to set it up with nginx, I think I've got it going now. Thanks for clearing that up.

adamdruppe commented 2 days ago

nginx has built in support for scgi reverse proxy too which you might prefer, you can easily start and stop the server there yourself as well.