Error on writeRequested

jsia24 jsia18 at gmail.com
Mon May 30 09:50:19 EDT 2011


when I add e.getChannel().close()

java.nio.channels.ClosedChannelException
        at
sun.nio.ch.SocketChannelImpl.ensureWriteOpen(SocketChannelImpl.java:133)
        at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:324)
        at
org.jboss.netty.channel.socket.nio.SocketSendBufferPool$PooledSendBuffer.transferTo(SocketSendBufferPool.java:239)
        at
org.jboss.netty.channel.socket.nio.NioWorker.write0(NioWorker.java:469)
        at
org.jboss.netty.channel.socket.nio.NioWorker.writeFromTaskLoop(NioWorker.java:392)
        at
org.jboss.netty.channel.socket.nio.NioSocketChannel$WriteTask.run(NioSocketChannel.java:276)
        at
org.jboss.netty.channel.socket.nio.NioWorker.processWriteTaskQueue(NioWorker.java:268)
        at
org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:199)
        at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:662)

it complains that it is writing to an open socket do I need to kill the
idletimer before closing the connection? if yes, how is it done? I wanted to
use persistent connection, am I still doing it right if I close the
connection?

On Mon, May 30, 2011 at 9:48 PM, Norman Maurer-2 [via Netty Forums and
Mailing Lists] <ml-node+6419199-2003162173-301197 at n2.nabble.com> wrote:

> Nope it will not close the connection. It will add a listener which
> will get fired on a event. If you want to close a connection you
> should use e.getChannel().close();
>
> Bye,
> Norman
>
>
> 2011/5/30 jsia24 <[hidden email]<http://user/SendEmail.jtp?type=node&node=6419199&i=0>>:
>
>
> > When I try to do this
> >
> > ChannelFuture future = e.getChannel().write(response);
> > future.addListener(ChannelFutureListener.CLOSE);
> >
> > it closes the connection right? It's an IdleStateListener, when i gets
> idle
> > i write a response then will the code above close that connection?
> >
> >
> > On Mon, May 30, 2011 at 9:37 PM, Trustin Lee [via Netty Forums and
> Mailing
> > Lists] <[hidden email]<http://user/SendEmail.jtp?type=node&node=6419199&i=1>>
> wrote:
> >
> >> Are you sure that you are not writing more responses than the number of
> >> received requests?  For example, sending more than one response for a
> >> single request is not right.
> >>
> >> On 05/30/2011 10:31 PM, jsia24 wrote:
> >>
> >> > I'm writing a comet server.
> >> >
> >> > On Mon, May 30, 2011 at 9:29 PM, Trustin Lee [via Netty Forums and
> >> Mailing
> >> > Lists]<[hidden email]<
> http://user/SendEmail.jtp?type=node&node=6419159&i=0>>
> >>  wrote:
> >> >
> >> >> Are you writing a server, or a client?
> >> >>
> >> >> On 05/30/2011 09:55 PM, jsia24 wrote:
> >> >>
> >> >>> Here it is:
> >> >>>       I am actually saving the MessageEvents in a HashMap and reply
> to
> >> >> them
> >> >>> when there is an event so what I did is to send a default message
> when
> >> it
> >> >>
> >> >>> did not receive an event for a period of time,  it does not produce
> an
> >> >> error
> >> >>> if I do not write any response to the IdleStateEvent e ( if I just
> do
> >> >>> e.getChannel.close() )
> >> >>>
> >> >>> java.lang.IllegalStateException: cannot send more responses than
> >> requests
> >> >>
> >> >>>           at
> >> >>>
> >> >>
> >>
> org.jboss.netty.handler.codec.http.HttpContentEncoder.writeRequested(HttpContentEncoder.java:102)
>
> >>
> >> >>
> >> >>>           at
> org.jboss.netty.channel.Channels.write(Channels.java:611)
> >> >>>           at
> org.jboss.netty.channel.Channels.write(Channels.java:578)
> >> >>>           at
> >> >>>
> org.jboss.netty.channel.AbstractChannel.write(AbstractChannel.java:259)
> >>
> >> >>>           at
> >> >> org.comet.classes.IdleHandler.channelIdle(IdleHandler.java:31)
> >> >>>           at
> >> >>>
> >> >>
> >>
> org.jboss.netty.handler.timeout.IdleStateAwareChannelHandler.handleUpstream(IdleStateAwareChannelHandler.java:46)
>
> >>
> >> >>
> >> >>>           at
> >> >>>
> >> >>
> >>
> org.jboss.netty.handler.timeout.IdleStateHandler.channelIdle(IdleStateHandler.java:324)
>
> >>
> >> >>
> >> >>>           at
> >> >>>
> >> >>
> >>
> org.jboss.netty.handler.timeout.IdleStateHandler$WriterIdleTimeoutTask.run(IdleStateHandler.java:382)
>
> >>
> >> >>
> >> >>>           at
> >> >>>
> >> >>
> >>
> org.jboss.netty.util.HashedWheelTimer$HashedWheelTimeout.expire(HashedWheelTimer.java:519)
>
> >>
> >> >>
> >> >>>           at
> >> >>>
> >> >>
> >>
> org.jboss.netty.util.HashedWheelTimer$Worker.notifyExpiredTimeouts(HashedWheelTimer.java:440)
>
> >>
> >> >>
> >> >>>           at
> >> >>>
> >> >>
> >>
> org.jboss.netty.util.HashedWheelTimer$Worker.run(HashedWheelTimer.java:379)
> >> >>>           at java.lang.Thread.run(Thread.java:662)
> >> >>>
> >> >>> public class IdleHandler extends IdleStateAwareChannelHandler {
> >> >>>        public void channelIdle(ChannelHandlerContext ctx,
> >> IdleStateEvent
> >> >> e) {
> >> >>>            HttpResponse response = new DefaultHttpResponse(HTTP_1_1,
>
> >> OK);
> >> >>>            response.setContent(ChannelBuffers.copiedBuffer("{}",
> >> >>> CharsetUtil.UTF_8));
> >> >>>            response.setHeader(CONTENT_TYPE, "text/plain;
> >> charset=UTF-8");
> >> >>>            response.setHeader(CONTENT_LENGTH,
> >> >>> response.getContent().readableBytes());
> >> >>>            response.setHeader("Access-Control-Allow-Origin", "*");
> >> >>>            ChannelFuture future = e.getChannel().write(response);
> >> >>>            future.addListener(ChannelFutureListener.CLOSE);
> >> >>>        }
> >> >>> }
> >> >>>
> >> >>> On Mon, May 30, 2011 at 3:16 PM, Norman Maurer-2 [via Netty Forums
> and
> >> >>> Mailing Lists]<[hidden email]<
> >> http://user/SendEmail.jtp?type=node&node=6419124&i=0>>
> >> >>   wrote:
> >> >>>
> >> >>>> Can you post the stacktrace and your code?
> >> >>>>
> >> >>>> Thanks
> >> >>>> Norman
> >> >>>>
> >> >>>> 2011/5/30, jsia24<[hidden email]<
> >> >> http://user/SendEmail.jtp?type=node&node=6418081&i=0>>:
> >> >>>>
> >> >>>>
> >> >>>>> Hi ,
> >> >>>>>
> >> >>>>>       When I try to send a response on the IdleHandler, it is
> >> producing
> >> >> an
> >> >>>>> error:  cannot send more responses than requests. Could anyone
> help
> >> on
> >> >>>> how
> >> >>>>> to resolve this?
> >> >>>>>
> >> >>>>> --
> >> >>>>> View this message in context:
> >> >>>>>
> >> >>>>
> >> >>
> >>
> http://netty-forums-and-mailing-lists.685743.n2.nabble.com/Error-on-writeRequested-tp6418009p6418009.html
> >> >>>>> Sent from the Netty User Group mailing list archive at Nabble.com.
>
> >> >>>>> _______________________________________________
> >> >>>>> netty-users mailing list
> >> >>>>> [hidden email]<
> http://user/SendEmail.jtp?type=node&node=6418081&i=1>
> >>
> >> >>>>> https://lists.jboss.org/mailman/listinfo/netty-users
> >> >>>>>
> >> >>>> _______________________________________________
> >> >>>> netty-users mailing list
> >> >>>> [hidden email]<
> http://user/SendEmail.jtp?type=node&node=6418081&i=2>
> >> >>>> https://lists.jboss.org/mailman/listinfo/netty-users
> >> >>>>
> >> >>>>
> >> >>>> ------------------------------
> >> >>>>    If you reply to this email, your message will be added to the
> >> >> discussion
> >> >>>> below:
> >> >>>>
> >> >>>>
> >> >>
> >> >>>>
> >> >>>>
> >> >>>
> >> >>>
> >> >>> --
> >> >>> View this message in context:
> >> >>
> >>
> http://netty-forums-and-mailing-lists.685743.n2.nabble.com/Error-on-writeRequested-tp6418009p6418985.html
> >> >>
> >> >>> Sent from the Netty User Group mailing list archive at Nabble.com.
> >> >>> _______________________________________________
> >> >>> netty-users mailing list
> >> >>> [hidden email]<http://user/SendEmail.jtp?type=node&node=6419124&i=1>
>
> >> >>> https://lists.jboss.org/mailman/listinfo/netty-users
> >> >>
> >> >>
> >> >> --
> >> >> Trustin Lee, http://gleamynode.net/
> >> >> _______________________________________________
> >> >> netty-users mailing list
> >> >> [hidden email]<http://user/SendEmail.jtp?type=node&node=6419124&i=2>
>
> >> >> https://lists.jboss.org/mailman/listinfo/netty-users
> >> >> what we call human nature in actuality is human habit
> >> >> http://gleamynode.net/
> >> >>
> >> >>
> >> >> ------------------------------
> >> >>   If you reply to this email, your message will be added to the
> >> discussion
> >> >> below:
> >> >>
> >> >>
> >>
> >> >>
> >> >>
> >> >
> >> >
> >> > --
> >> > View this message in context:
> >>
> http://netty-forums-and-mailing-lists.685743.n2.nabble.com/Error-on-writeRequested-tp6418009p6419138.html
> >>
> >> > Sent from the Netty User Group mailing list archive at Nabble.com.
> >> > _______________________________________________
> >> > netty-users mailing list
> >> > [hidden email] <http://user/SendEmail.jtp?type=node&node=6419159&i=1>
>
> >> > https://lists.jboss.org/mailman/listinfo/netty-users
> >>
> >>
> >> --
> >> Trustin Lee, http://gleamynode.net/
> >> _______________________________________________
> >> netty-users mailing list
> >> [hidden email] <http://user/SendEmail.jtp?type=node&node=6419159&i=2>
> >> https://lists.jboss.org/mailman/listinfo/netty-users
> >> what we call human nature in actuality is human habit
> >> http://gleamynode.net/
> >>
> >>
> >> ------------------------------
> >>  If you reply to this email, your message will be added to the
> discussion
> >> below:
> >>
> >>
>
> >>
> >>
> >
> >
> > --
> > View this message in context:
> http://netty-forums-and-mailing-lists.685743.n2.nabble.com/Error-on-writeRequested-tp6418009p6419169.html
>
> > Sent from the Netty User Group mailing list archive at Nabble.com.
> > _______________________________________________
> > netty-users mailing list
> > [hidden email] <http://user/SendEmail.jtp?type=node&node=6419199&i=2>
> > https://lists.jboss.org/mailman/listinfo/netty-users
> >
>
> _______________________________________________
> netty-users mailing list
> [hidden email] <http://user/SendEmail.jtp?type=node&node=6419199&i=3>
> https://lists.jboss.org/mailman/listinfo/netty-users
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://netty-forums-and-mailing-lists.685743.n2.nabble.com/Error-on-writeRequested-tp6418009p6419199.html
>  To unsubscribe from Error on writeRequested, click here<http://netty-forums-and-mailing-lists.685743.n2.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=6418009&code=anNpYTE4QGdtYWlsLmNvbXw2NDE4MDA5fDE0MTk5NTMxMjM=>.
>
>


--
View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/Error-on-writeRequested-tp6418009p6419211.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list