users@grizzly.java.net

RE: Grizzly Suspend

From: Gay David (Annecy) <"Gay>
Date: Tue, 28 Jun 2011 13:32:04 +0000

Hi all,

I'm back to the code ... :-) I'm still fighting with my issue with Grizzly.
I was able to made some progress and see and fix some bad exception management in my code.
I now have less problem. But still have this one on heavy load :

2011-06-28 15:18:43,320 GMT+0200 - [Grizzly-8090(2)] WARN (AdapterMapper.service:156) - Error while servicing HTTP request
java.lang.NullPointerException
         at com.sun.grizzly.tcp.SuspendResponseUtils.attach(SuspendResponseUtils.java:61)
         at com.sun.grizzly.tcp.Response.suspend(Response.java:945)
         at com.sun.grizzly.tcp.Response.suspend(Response.java:884)
         at com.axway.drw.core.http.internal.AdapterMapper.service(AdapterMapper.java:122)
         at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:822)
         at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:719)
         at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1013)
         at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
         at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
         at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
         at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
         at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
         at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
         at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
         at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
         at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
         at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
         at java.lang.Thread.run(Thread.java:662)

The line 945_at_Response is this one :

SuspendResponseUtils.attach(selectionKey, ra);

And it fails with a NPE inside SuspendResponseUtils.attach(...) because obviously, the selectionKey attribute of the response object pass in the method service(...) is null !

Could someone that know well the Grizzly internal gives me some hint or clue, of what could be the cause of this situation ?
I'm sure I am doing something wrong, but right now, still unable to reproduce with a simple test case.

Thanks and regards
David

De : Gay David (Annecy)
Envoyé : mercredi 15 juin 2011 17:02
À : 'users_at_grizzly.java.net'
Objet : Grizzly Suspend

Hi all,

I'm using Grizzly 1.9.35 and I have a problem with the suspend/resume feature.
Basically, I delegate to some threads the Grizzly request.
So, in my adapter, in the method service( request, response ) I do :
- response.suspend( ... )
- give the request to my own worker, and when it's finish, call response.resume()

Sometimes, under heavy load, I have a problem, when I ask to suspend the request I have this error :

2011-06-15 16:06:39,340 GMT+0200 - [Grizzly-8090(4)] ERROR (AdapterMapper.service:122) - Error while trying to suspend a request
java.lang.NullPointerException
         at com.sun.grizzly.tcp.SuspendResponseUtils.attach(SuspendResponseUtils.java:61)
         at com.sun.grizzly.tcp.Response.suspend(Response.java:945)
         at com.sun.grizzly.tcp.Response.suspend(Response.java:884)
         at com.axway.drw.core.http.internal.AdapterMapper.service(AdapterMapper.java:118)
         at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:822)
         at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:719)
         at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1013)
         at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
         at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
         at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
         at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
         at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
         at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
         at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
         at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
         at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
         at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
         at java.lang.Thread.run(Thread.java:662)

I should do something wrong somewhere.

Can someone suggest me what could be the cause of this error ?
Maybe this error suggest that a miss to resume somewhere ?
Could it be a Grizzly problem ?

This is a simplify code of my adapter :

@Override
public void service( Request req, Response res ) throws Exception {

         try {
                   res.suspend( Long.MAX_VALUE, someDataForTheCompletion, new MyCompletionHandler(req,res) );
         }
         catch ( Exception ex ) {
                   log.log( SEVERE, "Error while trying to suspend a request", ex );
         }

         try {
AsynchronousRequest asyncReq = new AsynchronousRequest( req, res );
                   getMyExecutor().register( asyncReq );
         }
         catch( RejectedExecutionException ex ) {
                   res.setStatus( 509 );
                   res.setMessage( "Too many requests" );
                   res.resume();
                   log.log( INFO, "Asynchronous request cannot be treated by the server: too many requests" );
         }
}

As you see, if my executor is too busy, it set an http error and resume the response. It means that sometimes, the resume is in the Grizzly thread, sometimes not.


Thanks for any help
Regards, David.