# HTTP status code 499 from long running requests

**URL:** <https://www.ruby-forum.com/t/http-status-code-499-from-long-running-requests/235138>\
**Category:** NGINX\
**Created:** [June 2, 2013, 3:10am UTC](https://www.ruby-forum.com/t/http-status-code-499-from-long-running-requests/235138 "2013-06-02T03:10:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [June 2, 2013, 3:10am UTC](https://www.ruby-forum.com/t/http-status-code-499-from-long-running-requests/235138/1 "2013-06-02T03:10:10Z")

</div>

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?

Thanks for the help with this.

Posted at Nginx Forum:

> **[HTTP status code 499 from long running requests](https://forum.nginx.org/read.php?2,239759,239759#msg-239759)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![justin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ab097/32.png) [@justin](https://www.ruby-forum.com/u/justin)\
**Post date:** [June 2, 2013, 1:04pm UTC](https://www.ruby-forum.com/t/http-status-code-499-from-long-running-requests/235138/2 "2013-06-02T13:04:55Z")

</div>

Hello!

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.

–  
Maxim D.

> **[nginx: donation](http://nginx.org/en/donation.html)**

---

<div class="post-metadata">

**Author:** ![justin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ab097/32.png) [@justin](https://www.ruby-forum.com/u/justin)\
**Post date:** [June 4, 2013, 6:52am UTC](https://www.ruby-forum.com/t/http-status-code-499-from-long-running-requests/235138/3 "2013-06-04T06:52:26Z")

</div>

Maxim,

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
> 
> –  
> Maxim D.  
> [nginx: donation](http://nginx.org/en/donation.html)
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,239759,239819#msg-239819](http://forum.nginx.org/read.php?2,239759,239819#msg-239819)

---

<div class="post-metadata">

**Author:** ![justin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ab097/32.png) [@justin](https://www.ruby-forum.com/u/justin)\
**Post date:** [June 4, 2013, 1:28pm UTC](https://www.ruby-forum.com/t/http-status-code-499-from-long-running-requests/235138/4 "2013-06-04T13:28:36Z")

</div>

Hello!

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.

–  
Maxim D.

> **[nginx: donation](http://nginx.org/en/donation.html)**

---

<div class="post-metadata">

**Author:** ![justin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ab097/32.png) [@justin](https://www.ruby-forum.com/u/justin)\
**Post date:** [June 7, 2013, 4:42pm UTC](https://www.ruby-forum.com/t/http-status-code-499-from-long-running-requests/235138/5 "2013-06-07T16:42:46Z")

</div>

Hello!

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](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.

–  
Maxim D.

> **[nginx: donation](http://nginx.org/en/donation.html)**

---

<div class="post-metadata">

**Author:** ![justin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ab097/32.png) [@justin](https://www.ruby-forum.com/u/justin)\
**Post date:** [June 7, 2013, 6:24am UTC](https://www.ruby-forum.com/t/http-status-code-499-from-long-running-requests/235138/6 "2013-06-07T06:24:05Z")

</div>

Maxim,

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](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](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?

Thanks for the help.

Posted at Nginx Forum:

> **[Re: HTTP status code 499 from long running requests](https://forum.nginx.org/read.php?2,239759,239943#msg-239943)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![shabijkh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90db22/32.png) [@shabijkh](https://www.ruby-forum.com/u/shabijkh)\
**Post date:** [May 31, 2021, 7:43am UTC](https://www.ruby-forum.com/t/http-status-code-499-from-long-running-requests/235138/7 "2021-05-31T07:43:16Z")

</div>

Hi  
I have faced this problem recently. Could you solve it? I’m working on financial systems and running twice of transactions is real problem for me
