You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Lucas <ma...@gmail.com> on 2013/08/10 13:54:32 UTC
Detection "connection reset by peer" in mod_perl before send a response
Dear all.
I need to detect that user pressed escape, apache receives it like "connection reset by peer" (I saw
it with truss, freebsd strace), before my script will send a response to client.
I can explain: my script works some time (about 2-3 sec), it gathers some data. Within this period
it is possible that user decide to press escape or even to close the page or browser.
I need to detect it and clean some temporary files, what is normally happen by additional request
from script on the page.
I need your advice how to do it.
Thanks.
Re: Detection "connection reset by peer" in mod_perl before send
a response
Posted by Torsten Förtsch <to...@gmx.net>.
On 10/08/13 15:19, Lucas wrote:
> But if apache receives "connection reset by peer" I would like to handle
> it with mod_perl.
>
> And my question was - how to do that.
http://foertsch.name/ModPerl-Tricks/postgres-notifications/index.shtml#goto8
Have a look at the wait_for_notification function.
Torsten
Re: Detection "connection reset by peer" in mod_perl before send
a response
Posted by Lucas <ma...@gmail.com>.
> So basically, you need to revise the logic of your application so that it does not depend on any
> kind of signal coming back from the browser, because there is no guarantee that you will ever get
> such a signal back.
I would like to start from this part of your replay.
Page that client get mainly use ajax, and most of it requests go through ajax, which works on client
side.
And if client won't request anything any more by any reason, apache will not answer.
But if apache receives "connection reset by peer" I would like to handle it with mod_perl.
And my question was - how to do that.
Thanks.
Re: Detection "connection reset by peer" in mod_perl before send
a response
Posted by André Warnier <aw...@ice-sa.com>.
Lucas wrote:
> Dear all.
>
> I need to detect that user pressed escape, apache receives it like
> "connection reset by peer" (I saw it with truss, freebsd strace), before
> my script will send a response to client.
>
> I can explain: my script works some time (about 2-3 sec), it gathers
> some data. Within this period it is possible that user decide to press
> escape or even to close the page or browser.
>
> I need to detect it and clean some temporary files, what is normally
> happen by additional request from script on the page.
>
> I need your advice how to do it.
>
First, you need to think about the whole setup between your script and the user's browser,
like this (1 line) :
script <-> perl <-> Apache <-> network <-> firewall/proxy <-> internet <-> internet <->
.... <-> firewall/proxy <-> user browser
Any of the "things" between your script and the user's browser has buffers, and may be
setting up separate TCP connections in-between. It's not like your script is directly
connected to the user's browser in any way.
In other words, if the user "walks away" from your page at any time, there is no guarantee
that your Apache server (and even less your script) would get any kind of signal back,
indicating that the user has done that.
The only time when your script can know that the user "has gone away", is if your script
tries to write something to the connection at the end of which is the user's browser, and
it gets back an error from Apache/perl saying that there is no connection anymore, and
that the write could not happen.
And even Apache/perl may not necessarily know that the user has gone away, because they
may have finished writing to the network, and the response may be somewhere still in a
buffer somewhere along the way.
So basically, you need to revise the logic of your application so that it does not depend
on any kind of signal coming back from the browser, because there is no guarantee that you
will ever get such a signal back.
That can be complicated, but that is simply how HTTP works, and there is nothing that you
can do to change that.
If you cannot/do not want to do this, then you need to think about another way than HTTP
to connect your application with the user's browser, such as "websockets" e.g.
Re: Detection "connection reset by peer" in mod_perl before send
a response
Posted by Andy Colson <an...@squeakycode.net>.
On 08/10/2013 06:54 AM, Lucas wrote:
> Dear all.
>
> I need to detect that user pressed escape, apache receives it like "connection reset by peer" (I saw it with truss, freebsd strace), before my script will send a response to client.
>
> I can explain: my script works some time (about 2-3 sec), it gathers some data. Within this period it is possible that user decide to press escape or even to close the page or browser.
>
> I need to detect it and clean some temporary files, what is normally happen by additional request from script on the page.
>
> I need your advice how to do it.
>
> Thanks.
I wrap an eval around it and ignore the error:
eval {
$r->print($buf);
};
unlink($tempfiles);
-Andy