AJAX request times out after 1 minute

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:

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

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

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


Maybe you want to schedule jobs to process the import.


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


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