WebRequestPromiseDecorator and long-running tasks

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

WebRequestPromiseDecorator and long-running tasks

sdwr
Hi all,

A fairly obscure issue here, but one that's blocking how I'm trying to do things.  Here's what my controller tries to do:

    def index() {
    	def promise = task {
            try {
                Thread.sleep(1000)
                return "ABCD"
            } catch (err) {
                println("Caught error during task")
                err.printStackTrace()
                throw err
            } 
        }
        
        promise.onComplete { result ->
            println("onComplete")
        }
        
        promise.onError { err ->
            println("onError")
        }

        render "Index"

It kicks off a long-running task, then registers an onComplete and onError handler.  If the call to Thread.sleep isn't there, everything works as promised.  But when the Thread.sleep is there and is long enough to cause the task to take longer than the actual request, problems arise.  The actual displayed error is this:

| Error 2013-11-15 12:08:47,087 [Actor Thread 5] ERROR gpars.LoggingPoolFactory  - Async execution error: null
Message: null
    Line | Method
->>   72 | doCall    in org.grails.async.factory.gpars.GparsPromise$_onError_closure2
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|     62 | run       in groovyx.gpars.dataflow.DataCallback$1
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run . . . in java.lang.Thread

but, after much, much digging, it turns out that the real culprit is this:

| Error java.lang.NullPointerException
| Error 	at org.apache.catalina.connector.Request.notifyAttributeAssigned(Request.java:1563)
| Error 	at org.apache.catalina.connector.Request.setAttribute(Request.java:1554)
| Error 	at org.apache.catalina.connector.RequestFacade.setAttribute(RequestFacade.java:542)
| Error 	at org.apache.catalina.core.ApplicationHttpRequest.setAttribute(ApplicationHttpRequest.java:281)
| Error 	at org.codehaus.groovy.grails.web.util.WebUtils.storeGrailsWebRequest(WebUtils.java:682)
| Error 	at org.codehaus.groovy.grails.plugins.web.async.WebRequestPromsiseDecorator$_decorate_closure1.doCall(WebRequestPromiseDecoratorLookupStrategy.groovy:61)
| Error 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| Error 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
| Error 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
| Error 	at java.lang.reflect.Method.invoke(Method.java:601)
| Error 	at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1260)
| Error 	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
| Error 	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
| Error 	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1086)
| Error 	at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1110)
| Error 	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:910)
| Error 	at groovy.lang.Closure.call(Closure.java:411)
| Error 	at groovy.lang.Closure.call(Closure.java:405)
| Error 	at groovyx.gpars.group.PGroup$3.call(PGroup.java:287)
| Error 	at groovyx.gpars.group.PGroup$4.run(PGroup.java:311)
| Error 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
| Error 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
| Error 	at java.lang.Thread.run(Thread.java:722)

What it looks like to me is that the WebRequestPromiseDecorator is running the closure and after it's done, trying to set the current web request context back to its original state - the problem is that the request has finished and things are in a not-good state.  

I guess I have 2 questions - am I just doing something wrong? Or is this a bug in how the task is being set up?

Thanks,
Scott
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: WebRequestPromiseDecorator and long-running tasks

andrey onistchuk
Hello!

A am getting the same errors now!
Have you already solved this?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: WebRequestPromiseDecorator and long-running tasks

Graeme Rocher-2
If one of you can attach an example to a JIRA issue we can take a look

thx

On Fri, Feb 14, 2014 at 11:15 AM, andrey onistchuk <[hidden email]> wrote:

> Hello!
>
> A am getting the same errors now!
> Have you already solved this?
>
>
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/WebRequestPromiseDecorator-and-long-running-tasks-tp4651540p4654116.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>



--
Graeme Rocher
Grails Project Lead
SpringSource

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: WebRequestPromiseDecorator and long-running tasks

jesicacornejo
Some of you found how to solve this?
I have the same error.
Loading...