Hello, I have long running requests upwards of five minutes that are
called
via ajax (jQuery) (XHR), and hitting a backend PHP script.
I am seeing very strange behavior, intermittently calling the script
twice,
even though in Chrome developers tools I only see a single XHR request
in
the network pane. I know that it is running twice because in my backend
PHP
script I write a log to a MySQL database, and I am seeing two entries.
I took a look at the nginx access log, and seeing HTTP status code 499,
which seems to be: client closed connection before nginx
was able to send anything to client.
What is the best way to fix this? Is there a config setting in nginx to
keep
the connection open? Or is the client terminating the request, and then
reissuing the request, thus way I am seeing two entries?
On Sat, Jun 01, 2013 at 09:09:55PM -0400, justin wrote:
was able to send anything to client.
What is the best way to fix this? Is there a config setting in nginx to keep
the connection open? Or is the client terminating the request, and then
reissuing the request, thus way I am seeing two entries?
The 499 code means that client closed connection, and there is
more or less nothing you can do from nginx side. You have to
either find a way to ask client to wait longer before it gives up,
or return something before it gives up.
Does it seem reasonable that the 499 status codes are responsible for
double
requests? I.E. do you think the client is resending the request after
the
499 status?
Maxim D. Wrote:
even though in Chrome developers tools I only see a single XHR
On Tue, Jun 04, 2013 at 12:52:03AM -0400, justin wrote:
Does it seem reasonable that the 499 status codes are responsible for double
requests? I.E. do you think the client is resending the request after the
499 status?
No. But both 499 status codes (i.e. client closed connection) and
double requests are likely happen because client times out.
On Fri, Jun 07, 2013 at 12:23:34AM -0400, justin wrote:
XX.XXX.XXX.253 - - [06/Jun/2013:21:11:32 -0700] “POST /actions/execute.php
HTTP/1.1” 200 673 “https://dev.mydomain.com/execute” “Mozilla/5.0
(Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/27.0.1453.110 Safari/537.36”
Just a side note: from the log there is no reason to assume these
requests are duplicate.
I obviously need a solution, since I am essentially creating duplicate
transactions. This only happens when the execute.php takes a long time
though. In jQuery when I am making the AJAX request I am setting the timeout
to 15 minutes. Is there anything else I can look at or try?
I would recommend reproducing the issue on a client, and looking
into network traffic via tcpdump / browser details via built in
tools to see why duplicate requests are sent.
On the other hand, duplicate POSTs aren’t at all new - they used
to happen due to users pressing “Submit” button multiple times.
An obvious solution is to use some one-time form tokens.
I dug a bit deeper and here is the nginx access log showing the 499
status
request, and then a repost of the same request:
XX.XX.XXX.253 - - [06/Jun/2013:21:09:08 -0700] “POST
/actions/execute.php
HTTP/1.1” 499 0 “https://dev.mydomain.com/execute” “Mozilla/5.0
(Macintosh;
Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/27.0.1453.110 Safari/537.36”
XX.XXX.XXX.253 - - [06/Jun/2013:21:11:32 -0700] “POST
/actions/execute.php
HTTP/1.1” 200 673 “https://dev.mydomain.com/execute” “Mozilla/5.0
(Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like
Gecko)
Chrome/27.0.1453.110 Safari/537.36”
I obviously need a solution, since I am essentially creating duplicate
transactions. This only happens when the execute.php takes a long time
though. In jQuery when I am making the AJAX request I am setting the
timeout
to 15 minutes. Is there anything else I can look at or try?