# AJAX request times out after 1 minute

**URL:** https://meta.discourse.org/t/ajax-request-times-out-after-1-minute/285873
**Category:** Development
**Created:** [November 17, 2023, 4:31pm UTC](https://meta.discourse.org/t/ajax-request-times-out-after-1-minute/285873 "2023-11-17T16:31:03Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![tomve](https://avatars.discourse-cdn.com/v4/letter/t/9f8e36/32.png) [@tomve](https://meta.discourse.org/u/tomve)
#### Post date: [November 17, 2023, 4:31pm UTC](https://meta.discourse.org/t/ajax-request-times-out-after-1-minute/285873/1 "2023-11-17T16:31:03Z")

</div>

A while I ago I created a Discourse plugin which calls a controller method via `ajax` and then returns the result. This particular request can run for a few minutes, and this was running fine.  
But now after a long while I tried the plugin in the current Discourse version and I’m running into an issue where the request is aborted after 1 minute.

So the code looks like this:

```plaintext
ajax("/my-plugin/import", {
        type: "POST",
        data: {
          categoryId: this.categoryId,
          otherData: ...
        }
      }).then((result) => { ... });

```

And the error message I see after 1 minute is:

> Discourse Ember CLI Proxy Error
> 
> FetchError: request to [http://127.0.0.1:3000/my-plugin/import](http://127.0.0.1:3000/my-plugin/import) failed, reason: socket hang up  
> at ClientRequest. (file:///src/app/assets/javascripts/node\_modules/node-fetch/src/index.js:108:11)  
> at ClientRequest.emit (node:events:526:35)  
> at Socket.socketOnEnd (node:\_http\_client:525:9)  
> at Socket.emit (node:events:526:35)  
> at endReadableNT (node:internal/streams/readable:1359:12)  
> at process.processTicksAndRejections (node:internal/process/task\_queues:82:21)

What I’m trying to understand is why this behaviour might have changed in the past year? And if there is any option to change the timeout setting.

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [November 17, 2023, 4:51pm UTC](https://meta.discourse.org/t/ajax-request-times-out-after-1-minute/285873/2 "2023-11-17T16:51:17Z")

</div>

I don’t think there has been any recent change here. Discourse’s backend is configured to timeout requests after 60 seconds in development, or 30 seconds in production

> <https://github.com/discourse/discourse/blob/cdcf53573d5eb85254913d25a9ee118a5df7c2f2/config/unicorn.conf.rb#L28-L40>

It looks like this is configurable in development via the `UNICORN_TIMEOUT` env variable. But production is hard-coded to 30 seconds.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [November 17, 2023, 11:49pm UTC](https://meta.discourse.org/t/ajax-request-times-out-after-1-minute/285873/3 "2023-11-17T23:49:43Z")

</div>

Maybe you want to schedule jobs to process the import.

---

<div class="post-metadata">

### Author: ![tomve](https://avatars.discourse-cdn.com/v4/letter/t/9f8e36/32.png) [@tomve](https://meta.discourse.org/u/tomve)
#### Post date: [November 30, 2023, 12:46pm UTC](https://meta.discourse.org/t/ajax-request-times-out-after-1-minute/285873/4 "2023-11-30T12:46:59Z")

</div>

In the end I did rewrite it to handle the import in a scheduled job, which turned out to be a lot better.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [December 30, 2023, 12:47pm UTC](https://meta.discourse.org/t/ajax-request-times-out-after-1-minute/285873/5 "2023-12-30T12:47:38Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
