Hi all,
I am trying out the async features in Grails (using 3.3.0M1) and am wondering how to handle some things that aren't very clear.
I have a controller like this:
import static grails.async.web.WebPromises.*
class FooController {
task {
List foos
Foo.withNewSession {
foos = Foo.list()
}
respond foos, formats: ['json','xml']
}
}
This works and my AJAX client gets an asynchronously generated list of objects in JSON format.
But here's the problem: if an error happens, the client never gets any response. It just sits forever waiting. I imagine on the server side as well, there's some resource kept allocated, so we are looking at a memory leak or worse.
I tried putting in my own error handling:
import static grails.async.web.WebPromises.*
respond foos, formats: ['json','xml']
render status: 501, text: 'Something went wrong: ' + e
This does return status 501 to the client eventually. However it takes about 20 seconds before this happens. It is as if the response doesn't get flushed for that long or something similar. I also don't like this version very much because I am worried that an internal error before my task block executes would still leave the client hanging.
So I am curious, what is the story meant to be with error handling on this kind of async request? Is there a blessed way to do it, or is this up to me? And if it's up to me, any thoughts about the delay in the response sent to the client?
Thanks for any feedback or thoughts.
Cheers,
Simon