Integrating Smalltalk with Major Web Servers using FastCGI

Ned Konz ned at bike-nomad.com
Sun Oct 22 22:03:56 UTC 2000


Peter William Lount wrote:
> 
> Hi,
> 
> Remember that when using FastCGI the Smalltalk "application server" is a
> seperate process from the web servers processes. The ModFastCGI module
> component that is already written in C and embedded in the WebServers would
> responds to the signals you mentioned (see below). If you need to have
> those signals get to the FastCGI client there is an 'error' provision in
> the fast cgi protocol. Please see the FastCGI specification and other
> papers linked to at http://www.mod.smalltalk.org.

Oh. I was just looking at the following quote from
http://www.fastcgi.com/docs/faq.html , which gave me the impression that
we'd have to deal with USR1 and TERM to cope with mod_fastcgi.

-----
How should I handle signals?

All FastCGI applications should handle PIPE and TERM , mod_fastcgi spawned
applications should also handle USR1.

PIPE occurs when trying to write/print to a file descriptor that has been
closed.  Under mod_fastcgi, if a client aborts a connection before it completes
mod_fastcgi
does too.  At a minimum, SIGPIPE should be ignored (this is already setup in
applications spawned by mod_fastcgi).  Ideally, it should result in an early
abort of the
request handling within your application and a return to the top of the FastCGI
accept() loop.

USR1 may be received by FastCGI applications spawned by mod_fastcgi.  Apache
uses this signal to request a "graceful" process shutdown (e.g. its used by
"apachectl restart").  When mod_fastcgi's Process Manager receives USR1 it sends
TERM to all of the FastCGI applications it spawned and then exits (its gets
restarted by Apache).  This means that, under Apache/mod_fastcgi, a FastCGI
application that receives USR1 from Apache will also receive TERM from the
process manager.  FastCGI applications expected to be run under the control of
mod_fastcgi/Apache should handle USR1 by finishing any request in process and
then shutting down.

TERM is the standard signal sent to applications to request shutdown. 
Typically, this is considered a request for "clean" shutdown, i.e. finish
anything your in the
middle of (within reason), free resources such as database connections, and
exit.  When Apache receives TERM, it does not finish handling requests in
progress. 
Whether or not you finish any request in process when TERM is received is your
decision, but keep in mind that under mod_fastcgi/Apache the TERM may be a
"graceful" request in disguise.  I always finish any request in process before
exiting.

Handling signals can be tricky.  Consult the documentation for your language and
system for restrictions and idiosyncrasies.  In general, its always best to do
as
little as possible from within a signal handler.


-- 
Ned Konz
currently: Stanwood, WA
email:     ned at bike-nomad.com
homepage:  http://bike-nomad.com





More information about the Squeak-dev mailing list