Browser stop: no EPIPE recieved

Peter Åstrand <[email protected]>
Newsgroups gmane.comp.web.fastcgi.devel
Message-ID <[email protected]>
I'm trying to detect when the user presses "stop" in the browser, and
abort an operation in my FastCGI program that takes a long time. It
doesn't work. Despite several hours of debugging, I cannot find the
problem.

http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html says that
applications should recieve SIGPIPE when an http client aborts a request
before it completes, but:

* SIGPIPE will be sent by the time the application tries to write to the
Fastcgi socket, right? So, if the application does some work without
sending any data to the browser, the SIGPIPE will be delayed. (In my
application, I constantly write dots to the browser, so this should not be
a problem in my case.)

* Instead of listening for SIGPIPE, you can look out if EPIPE is returned
when writing to the FastCGI socket, right? In some environments, such as
Python, it's very hard to listen for SIGPIPE (the signal is ignored by
default, and even if you change this, it is re-ignored whenever you create
a new socket. This bug was fixed recently, though.)


The problem is: my application never recieves EPIPE. All send() operations
completes successfully, even though the user has pressed stop. Here's a
trace of the application:

[pid 23569] send(5, "\1\6\0\1\0\3\5\0.\n\n\0\0\0\0\0", 16, 0) = 16


I've traced Apache with mod_fastcgi as well. As far as I can see, it does
*not* close/shutdown the Fastcgi socket, even though the write to the
browser fails:

[pid 23050] select(15, [14], [], NULL, {0, 100000}) = 1 (in [14], left {0, 20000})
[pid 23050] read(14, "\1\6\0\1\0\3\5\0.\n\n\0\0\0\0\0", 8192) = 16
[pid 23050] select(15, [14], [], NULL, {0, 100000}) = 0 (Timeout)
[pid 23050] writev(12, [{"5d\r\n", 4}, {".\n\n.\n\n.\n\n.\n\n.\n\n.\n\n.\n\n.\n\n.\n\n.\n\n.\n"..., 93}, {"\r\n", 2}], 3) = -1 EPIPE (Broken pipe)
[pid 23050] --- SIGPIPE (Broken pipe) @ 0 (0) ---
[pid 23050] select(15, [14], [], NULL, {600, 0}) = 1 (in [14], left {599, 996000})
[pid 23050] read(14, "\1\6\0\1\0\3\5\0.\n\n\0\0\0\0\0", 8192) = 16
[pid 23050] select(15, [14], [], NULL, {0, 100000}) = 0 (Timeout)

To me, this looks like a bug in mod_fastcgi. Shouldn't it shut down the
socket, or send FCGI_ABORT_REQUEST?

I'm using httpd-2.0.51-2.9 (Apache) on Fedora 2, with mod_fastcgi 2.4.2.
The Fastcgi application is written in Python, using thcfgi.py.

Any ideas?
http://www.fastcgi.com/archives/fastcgi-developers/2004-February/003268.html
mentiones Apaches content-length filter. Could this be the cause of my
problem?

/Peter Åstrand <[email protected]>

___________________________________
fastcgi-developers mailing list
http://fastcgi.com/fastcgi-developers/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.