Grails Async & Error Handling

20 views
Skip to first unread message

Simon Sadedin

unread,
May 27, 2017, 7:23:23 PM5/27/17
to Grails Dev Discuss
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.*
 
class FooController {
  task {
    try {
        List foos
        Foo.withNewSession {
            foos = Foo.list()
        }
        respond foos, formats: ['json','xml']
    }
    catch(Exception e) {
        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

Graeme Rocher

unread,
May 30, 2017, 3:37:18 AM5/30/17
to grails-de...@googlegroups.com
Thanks for the feedback, this turned out to be a bug. Fixed by
https://github.com/grails/grails-async/commit/d99152bad4b1ec1c547c26a043d3b4f09f48d931
and will go into the next RC
> --
> You received this message because you are subscribed to the Google Groups
> "Grails Dev Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to grails-dev-disc...@googlegroups.com.
> To post to this group, send email to grails-de...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/grails-dev-discuss/a2d27b78-4e26-4437-9bbe-07721aba42cd%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Graeme Rocher
Reply all
Reply to author
Forward
0 new messages