Quantcast

Read Timeout and Port unifcation

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Read Timeout and Port unifcation

vetti07
Hi,
   I'm using Grizzly Port unification  for using same port for both http and a tcp service.  I have created the  http server using GrizzlyHttpServerFactory.createHttpServer(...). then registering an add on for TCP Protocol finder/filters. My TCP service has Two filters.

In one of my filter in handleRead() method I set the timeout as 10 seconds using ctx.getConnection().setReadTimeout(10, TimeUnit.SECONDS) and doing cxt.read() in a loop (cxt is the FilterChainContext). The idea was to keep reading data from client till it closes the connection. I'm facing two issues with this

1. cxt.read() is not timing out(Even after 30 mins )
2. In filter I have overridden handleClose() method which is never getting invoked. I tried using CloseListener which is working fine. Not sure why handleClose method on the filters are not invoked.


Thanks
ashok

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

Re: Read Timeout and Port unifcation

oleksiys
Administrator
Hi,

On 6/2/16 5:18 AM, vetti07 wrote:

> Hi,
>     I'm using Grizzly Port unification  for using same port for both http and
> a tcp service.  I have created the  http server using
> GrizzlyHttpServerFactory.createHttpServer(...). then registering an add on
> for TCP Protocol finder/filters. My TCP service has Two filters.
>
> In one of my filter in handleRead() method I set the timeout as 10 seconds
> using ctx.getConnection().setReadTimeout(10, TimeUnit.SECONDS) and doing
> cxt.read() in a loop (cxt is the FilterChainContext). The idea was to keep
> reading data from client till it closes the connection. I'm facing two
> issues with this
>
> 1. cxt.read() is not timing out(Even after 30 mins )
> 2. In filter I have overridden handleClose() method which is never getting
> invoked. I tried using CloseListener which is working fine. Not sure why
> handleClose method on the filters are not invoked.

In 2.3.x we keep PUFilter in the Connection filter chain forever, so it
makes a routing (pu) decision for every packet. So once connection is
closed - it can't figure out where to route this error, because there is
no packet payload to know where to route the error. So handleClose won't
work unfortunately.
However ctx.read() should work with timeout and it sounds like a bug.
Could you pls. share the testcase, so we can reproduce the problem.

Thank you.

WBR,
Alexey.

>
>
> Thanks
> ashok
>
>
>
>
>
> --
> View this message in context: http://grizzly.1045725.n5.nabble.com/Read-Timeout-and-Port-unifcation-tp5711028.html
> Sent from the Grizzly - Users mailing list archive at Nabble.com.

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

Re: Read Timeout and Port unifcation

vetti07
This post was updated on .
Hi Alexey,
              Thanks Alexey  and I'm extremly sorry for such a late response. Teh read timout is working now. I had the below code (extract)  in the filter with whch read timeout was having issue
        public NextAction handleRead(final FilterChainContext ctx) throws IOException {
                             Buffer input=ctx.getMessage();
                             ReadResult<Buffer, ?> rs = null;
                              boolean isComplete=false;
                             do {
                                String line = input.toStringContent();

                                isComplete=SomeAppHandler.handleCmd(line.getBytes());
                                 
                                if(!isComplete) {
                                ReadResult<Buffer, ?> rs = ctx.read();
                                input = rs.getMessage();
                                }
                             } while(!isComplete)
           return ctx.getInvokeAction();
       }

The read timeout start working after I Changed it to
                             do {
                                String line = input.toStringContent();
                                input.tryDispose();

                                isComplete=SomeAppHandler.handleCmd(line.getBytes());
                                 
                                if(!isComplete) {
                                ReadResult<Buffer, ?> rs = ctx.read();
                                input = rs.getMessage();
                                rs.recycle();
                                }
                             } while(!isComplete)

Thanks for your help!!

Note: With updated  code ctx.read() is throwing exception when the connection is getting closed by the client(exception is NOT thrown when grizzly closes the connection). For now I'm using this to do the clean up. It would have been wonderful  if we had option to configure connection timeout (not just read/write timeout) per connection when using port unification for non HTTP protocols.
Loading...