Grails Async & Error Handling

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Grails Async & Error Handling

Simon Sadedin
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

--
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 [hidden email].
To post to this group, send email to [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|

Re: Grails Async & Error Handling

Graeme Rocher-2
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

On Sun, May 28, 2017 at 1:23 AM, Simon Sadedin <[hidden email]> wrote:

> 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
>
> --
> 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 [hidden email].
> To post to this group, send email to [hidden email].
> 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

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/CAO_wNodQaboHnzbwJ59oBJ8dyVMiyvKSxQUVNm0%2Bsjcn%3D2STGg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.