Trying to detect aborted client requests

Guillermo Arias del Río <[email protected]> Thu, 27 Jun 2013 11:47:24 +0200
Newsgroups gmane.comp.web.fastcgi.devel
Message-ID <CAObQZoK5zbuYyjp1nqO4Hc3D=KwRjLDtPDryYz7kAmYV63g6fQ@mail.gmail.com>
--===============5582460959355978370==
Content-Type: multipart/alternative; boundary=e89a8f646c8b6c16ab04e01fa720

--e89a8f646c8b6c16ab04e01fa720
Content-Type: text/plain; charset=ISO-8859-1

Hi, all!

I'm developing a FastCGI application using Apache, mod_cgi and the fcgio.h
API. Everything works so far, but I'm failing to detect aborted
connections. We need to control them, because we are sometimes doing
expensive operations which have to be aborted when the user aborts the
request. I'm trying to use the SIGPIPE as indicated in the documentation,
but it doesn't seem to work.

This is my system configuration:

CLIENT: Makes a XMLHttpRequest from Javascript and aborts it with the abort()
method

SERVER:

Linux Debian 3.2.46-1 x86_64
Apache2 (2.2.22-13)
mod_fastcgi (SNAP-0910052141)

This is my mod_fastcgi configuration:

FastCgiExternalServer $file -idle-timeout 3000 -socket $socket

And this is my code:

void FastcgiServer::sigpipe_handler(int signo) {
        std::cerr << "PIPE SIGNAL RECEIVED" << std::endl;
}

void FastcgiServer::run(){
    FCGX_Request request_i;

    FCGX_Init();
    init();
    FCGX_InitRequest(&request_i, socketfd, 0);

    struct sigaction sa;
    sigemptyset(&sa.sa_mask);
    sa.sa_handler = sigpipe_handler;
    sa.sa_flags = 0;
    sigaction(SIGPIPE, &sa, NULL);

    RequestState state;
    while (FCGX_Accept_r(&request_i) == 0)
    {
            state.reset(request_i);
            this->state = &state;
            state.response->http_status.code = 200;
            try {
                    fill_request(request_i, *state.request);
...

If I send the signal with kill -13, I see the message, but if the client
aborts the connection nothing happens. The client socket of the
FastCGIApplication seems to remain open as well.

Can anybody help me? Thanks.

--e89a8f646c8b6c16ab04e01fa720
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><div><div><div>Hi, all!<br><br></div>I&#39;m developi=
ng a FastCGI application using Apache, mod_cgi and the fcgio.h API. Everyth=
ing works so far, but I&#39;m failing to detect aborted connections. We nee=
d to control them, because we are sometimes doing expensive operations whic=
h have to be aborted when the user aborts the request. I&#39;m trying to us=
e the SIGPIPE as indicated in the documentation, but it doesn&#39;t seem to=
 work. <br>

<br></div><div>This is my system configuration:<br></div><div><br>CLIENT: M=
akes a <code class=3D"">XMLHttpRequest </code>from Javascript and aborts it=
 with the <span style=3D"font-family:courier new,monospace">abort() </span>=
method<code class=3D""><br>

</code></div><br>SERVER:<br><div><br></div>Linux Debian 3.2.46-1 x86_64<br>=
</div>Apache2 (2.2.22-13)<br></div><div>mod_fastcgi (SNAP-0910052141)<br></=
div><div><br>This is my mod_fastcgi configuration:<br><br>FastCgiExternalSe=
rver $file -idle-timeout 3000 -socket $socket<br>

<br></div>And this is my code:<br><span style=3D"font-family:courier new,mo=
nospace"><br>void FastcgiServer::sigpipe_handler(int signo) {<br>=A0=A0=A0=
=A0=A0=A0=A0 std::cerr &lt;&lt; &quot;PIPE SIGNAL RECEIVED&quot; &lt;&lt; s=
td::endl;<br>

}<br></span><br><span style=3D"font-family:courier new,monospace">void Fast=
cgiServer::run(){<br>=A0=A0=A0 FCGX_Request request_i;<br><br>=A0=A0=A0 FCG=
X_Init();<br>=A0=A0=A0 init();<br>=A0=A0=A0 FCGX_InitRequest(&amp;request_i=
, socketfd, 0);<br><br>

=A0=A0=A0 struct sigaction sa;<br>=A0=A0=A0 sigemptyset(&amp;sa.sa_mask);<b=
r>=A0=A0=A0 sa.sa_handler =3D sigpipe_handler;<br>=A0=A0=A0 sa.sa_flags =3D=
 0;<br>=A0=A0=A0 sigaction(SIGPIPE, &amp;sa, NULL);<br></span><span style=
=3D"font-family:courier new,monospace"><br>

=A0=A0=A0 RequestState state;<br>=A0=A0=A0 while (FCGX_Accept_r(&amp;reques=
t_i) =3D=3D 0)<br>=A0=A0=A0 {<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 state.re=
set(request_i);<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 this-&gt;state =3D &am=
p;state;<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 state.response-&gt;http_statu=
s.code =3D 200;<br>

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 try {<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0 fill_request(request_i, *state.request);<br>...=
<br></span><br>If I send the signal with kill -13, I see the message, but i=
f the client aborts the connection nothing happens. The client socket of th=
e FastCGIApplication seems to remain open as well.<br>

<br>Can anybody help me? Thanks.<br></div>

--e89a8f646c8b6c16ab04e01fa720--

--===============5582460959355978370==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
FastCGI-developers mailing list
FastCGI-developers-xGejAJT2w6xVgU18Zptdi0EOCMrvLtNR@public.gmane.org
http://mailman.fastcgi.com/mailman/listinfo/fastcgi-developers

--===============5582460959355978370==--