Controller and timeouts
Hi,
I have a controller for an AJAX request that takes a long time to process and return to the browser. What I am observing is that, before the controller has a chance to end, the ajax request fails with 'net::ERR_EMPTY_RESPONSE' on the client (jquery client-side).
Now, I originally thought this was an issue with timeouts client-side, but I have increased that and I still get this empty response.
Might it be that Adonis is imposing a server-side maximum limit on requests after which it simply fails and returns an empty answer (which would explain the error message as Jquery cannot parse that as JSON).
Cheers, Donato
- What's the url you are calling from Ajax?
- Howz your routes.js file?
- Are you making the response via the controller method for the given route?
Url:
- http://localhost:3333/test
Route: Route.get('/test', 'TasksController.test')
Controller:
- test (request, response) { setTimeout(function() { response.json({ok:'ok'}) }, 120000) }
The setTimeout() simulates a longer call. if I go with 1 minute, everything works and I get the ok JSON response. I got with 2 minutes, and things break.
On a similar note, I'm confused on the usage of async functions with callbacks within a generator, not sure if that's the right way of doing it.
Why do you want to make the request wait for 2minutes?
Im using setTimeout() here just as an example. I'm performing a task that takes several minutes to return, the time it takes is not really under my control.
Http server in Node.js has a timeout, you can disable it or set it to higher value. https://nodejs.org/api/http.html#http_server_timeout
How to do it in AdonisJs
You can do it by getting the access to the raw HTTP server inside Listeners/Http.js file.https://github.com/adonisjs/adonis-app/blob/develop/app/Listeners/Http.js#L40
const Server = use('Adonis/Src/Server')
Server.getInstance().timeout = 0
That did the trick. Thanks a lot!
I'm really enjoying using AdonisJS and I'm new to Javascript really, so enjoying learning a new language as well. Still getting my head around the callback and asyc-based nature of the language, can certainly appreciate generators a lot!
A question: I understand in order to use generators you need a sort of generator runner, which is going to call next and so on... what do you use in AdonisJS? And how does that work when, from within a generator, you use a normal function with a callback?
@kyuz0 How async function works is a broad concept. I suggest you to join the gitter room and discuss about same.
Closing the issue since it works
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.