You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Supun Kamburugamuva <su...@gmail.com> on 2010/12/03 10:37:04 UTC

When a client closes the connection following exception is thrown

I have a server which uses the HTTPCore NIO. This works fine as long as
client behaves nicely. But if the client closes the connection this
exception is thrown.

java.io.IOException: Broken pipe
    at sun.nio.ch.FileDispatcher.write0(Native Method)
    at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:29)
    at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:100)
    at sun.nio.ch.IOUtil.write(IOUtil.java:71)
    at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:334)
    at
org.apache.http.impl.nio.reactor.SessionOutputBufferImpl.flush(SessionOutputBufferImpl.java:96)
    at
org.apache.http.impl.nio.DefaultNHttpServerConnection.produceOutput(DefaultNHttpServerConnection.java:194)
    at
org.apache.http.impl.nio.DefaultServerIOEventDispatch.outputReady(DefaultServerIOEventDispatch.java:153)
    at
org.apache.http.impl.nio.reactor.BaseIOReactor.writable(BaseIOReactor.java:185)
    at
org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:338)
    at
org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315)
    at
org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:275)
    at
org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104)
    at
org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:542)
    at java.lang.Thread.run(Thread.java:680)

I'm shutting down the connection in the NHttpServiceHandler's closed method.
But it seems there is data in the Session Buffer and, even though the
connection is closed HTTPCore tries to send this data. Any pointers that
guide me in the right direction will be greatly appreciated.

Thanks,
Supun..

Re: When a client closes the connection following exception is thrown

Posted by Supun Kamburugamuva <su...@gmail.com>.
Hi Oleg,

Now I'm closing the connection immediately. Thanks for the help.

Thanks,
Supun.

On Fri, Dec 3, 2010 at 10:28 PM, Supun Kamburugamuva <su...@gmail.com>wrote:

> On Fri, Dec 3, 2010 at 9:56 PM, Oleg Kalnichevski <ol...@apache.org>wrote:
>
>> On Fri, 2010-12-03 at 21:40 +0530, Supun Kamburugamuva wrote:
>> > It is HttpConnection#shutdown(). But the problem is this exception
>> happens
>> > before I call this method.
>> >
>> > Thanks,
>> > Supun..
>> >
>>
>> In this case one should shut down the connection immediately after
>> catching the I/O exception.
>>
>> Hi Oleg,
>
> Thanks for the quick response.
>
> So is this the expected behavior in case a client closes a connection in
> the middle of a message read?
>
> Thanks,
> Supun..
>
>
>> Oleg
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
>> For additional commands, e-mail: dev-help@hc.apache.org
>>
>>
>
>
> --
> Technical Lead, WSO2 Inc
> http://wso2.org
> supunk.blogspot.com
>
>
>


-- 
Technical Lead, WSO2 Inc
http://wso2.org
supunk.blogspot.com

Re: When a client closes the connection following exception is thrown

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Fri, 2010-12-03 at 22:28 +0530, Supun Kamburugamuva wrote:
> On Fri, Dec 3, 2010 at 9:56 PM, Oleg Kalnichevski <ol...@apache.org> wrote:
> 
> > On Fri, 2010-12-03 at 21:40 +0530, Supun Kamburugamuva wrote:
> > > It is HttpConnection#shutdown(). But the problem is this exception
> > happens
> > > before I call this method.
> > >
> > > Thanks,
> > > Supun..
> > >
> >
> > In this case one should shut down the connection immediately after
> > catching the I/O exception.
> >
> > Hi Oleg,
> 
> Thanks for the quick response.
> 
> So is this the expected behavior in case a client closes a connection in the
> middle of a message read?
> 

One cannot assume the connection to be in a consistent state in case of
an I/O exception of any kind. So, connection shutdown seems to be the
only option in such case.

Hope this helps

Oleg



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Re: When a client closes the connection following exception is thrown

Posted by Supun Kamburugamuva <su...@gmail.com>.
On Fri, Dec 3, 2010 at 9:56 PM, Oleg Kalnichevski <ol...@apache.org> wrote:

> On Fri, 2010-12-03 at 21:40 +0530, Supun Kamburugamuva wrote:
> > It is HttpConnection#shutdown(). But the problem is this exception
> happens
> > before I call this method.
> >
> > Thanks,
> > Supun..
> >
>
> In this case one should shut down the connection immediately after
> catching the I/O exception.
>
> Hi Oleg,

Thanks for the quick response.

So is this the expected behavior in case a client closes a connection in the
middle of a message read?

Thanks,
Supun..


> Oleg
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org
>
>


-- 
Technical Lead, WSO2 Inc
http://wso2.org
supunk.blogspot.com

Re: When a client closes the connection following exception is thrown

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Fri, 2010-12-03 at 21:40 +0530, Supun Kamburugamuva wrote:
> It is HttpConnection#shutdown(). But the problem is this exception happens
> before I call this method.
> 
> Thanks,
> Supun..
> 

In this case one should shut down the connection immediately after
catching the I/O exception. 

Oleg



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Re: When a client closes the connection following exception is thrown

Posted by Supun Kamburugamuva <su...@gmail.com>.
It is HttpConnection#shutdown(). But the problem is this exception happens
before I call this method.

Thanks,
Supun..

On Fri, Dec 3, 2010 at 5:20 PM, Oleg Kalnichevski <ol...@apache.org> wrote:

> On Fri, 2010-12-03 at 15:07 +0530, Supun Kamburugamuva wrote:
> > I have a server which uses the HTTPCore NIO. This works fine as long as
> > client behaves nicely. But if the client closes the connection this
> > exception is thrown.
> >
> > java.io.IOException: Broken pipe
> >     at sun.nio.ch.FileDispatcher.write0(Native Method)
> >     at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:29)
> >     at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:100)
> >     at sun.nio.ch.IOUtil.write(IOUtil.java:71)
> >     at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:334)
> >     at
> >
> org.apache.http.impl.nio.reactor.SessionOutputBufferImpl.flush(SessionOutputBufferImpl.java:96)
> >     at
> >
> org.apache.http.impl.nio.DefaultNHttpServerConnection.produceOutput(DefaultNHttpServerConnection.java:194)
> >     at
> >
> org.apache.http.impl.nio.DefaultServerIOEventDispatch.outputReady(DefaultServerIOEventDispatch.java:153)
> >     at
> >
> org.apache.http.impl.nio.reactor.BaseIOReactor.writable(BaseIOReactor.java:185)
> >     at
> >
> org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:338)
> >     at
> >
> org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315)
> >     at
> >
> org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:275)
> >     at
> >
> org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104)
> >     at
> >
> org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:542)
> >     at java.lang.Thread.run(Thread.java:680)
> >
> > I'm shutting down the connection in the NHttpServiceHandler's closed
> method.
> > But it seems there is data in the Session Buffer and, even though the
> > connection is closed HTTPCore tries to send this data. Any pointers that
> > guide me in the right direction will be greatly appreciated.
> >
> > Thanks,
> > Supun..
>
> Supun,
>
> What method do you use to close the connection: HttpConnection#close()
> or HttpConnection#shutdown()?
>
> Oleg
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org
>
>


-- 
Technical Lead, WSO2 Inc
http://wso2.org
supunk.blogspot.com

Re: When a client closes the connection following exception is thrown

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Fri, 2010-12-03 at 15:07 +0530, Supun Kamburugamuva wrote:
> I have a server which uses the HTTPCore NIO. This works fine as long as
> client behaves nicely. But if the client closes the connection this
> exception is thrown.
> 
> java.io.IOException: Broken pipe
>     at sun.nio.ch.FileDispatcher.write0(Native Method)
>     at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:29)
>     at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:100)
>     at sun.nio.ch.IOUtil.write(IOUtil.java:71)
>     at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:334)
>     at
> org.apache.http.impl.nio.reactor.SessionOutputBufferImpl.flush(SessionOutputBufferImpl.java:96)
>     at
> org.apache.http.impl.nio.DefaultNHttpServerConnection.produceOutput(DefaultNHttpServerConnection.java:194)
>     at
> org.apache.http.impl.nio.DefaultServerIOEventDispatch.outputReady(DefaultServerIOEventDispatch.java:153)
>     at
> org.apache.http.impl.nio.reactor.BaseIOReactor.writable(BaseIOReactor.java:185)
>     at
> org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:338)
>     at
> org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315)
>     at
> org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:275)
>     at
> org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104)
>     at
> org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:542)
>     at java.lang.Thread.run(Thread.java:680)
> 
> I'm shutting down the connection in the NHttpServiceHandler's closed method.
> But it seems there is data in the Session Buffer and, even though the
> connection is closed HTTPCore tries to send this data. Any pointers that
> guide me in the right direction will be greatly appreciated.
> 
> Thanks,
> Supun..

Supun,

What method do you use to close the connection: HttpConnection#close()
or HttpConnection#shutdown()?

Oleg



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org