AtmosphereEvents are not getting removed even after connections are closed - Tomcat

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

AtmosphereEvents are not getting removed even after connections are closed - Tomcat

abeytom
Salut,

The issue which I see is that the AtmosphereEvents are added to the DefaultBroadcaster.events with each refresh in the page and are not getting removed.

I think this issue kind is similar to
a)http://n2.nabble.com/onMessage-method-is-not-called-td2743248.html
b)http://n2.nabble.com/atmosphere-chat-on-tomcat-threw-java.lang.NullPointerException-td2677192.html
I'm creating a new post bcos those two issues were fixed and I'm getting issues with the latest code.

I'm working with the sample application https://www.dev.java.net/svn/atmosphere/trunk/atmosphere/samples/chat in apache-tomcat-6.0.18.I built latest the atmosphere code from the trunk.

To reproduce the issue please follow the below steps.
1. Hit the url http://<ip>/atmosphere-chat/index.html(IE, Firefox) - This will invoke the AtmosphereHandler.onEvent(AtmosphereEvent) where we suspend the event and the event gets added to the DefaultBroadcaster.events. So the size() of  DefaultBroadcaster.events will be 1. The stacktrace for that call is :

        DefaultBroadcaster.addAtmosphereEvent(AtmosphereEventImpl) line: 140
        DefaultBroadcaster.addAtmosphereEvent(AtmosphereEvent) line: 56
        AtmosphereEventImpl.suspend(long) line: 138
        AtmosphereEventImpl.suspend() line: 128
        ChatAtmosphereHandler.onEvent(AtmosphereEvent<HttpServletRequest,HttpServletResponse>) line: 92
        TomcatCometSupport(WebContainer).action(HttpServletRequest, HttpServletResponse) line: 126
        TomcatCometSupport(WebContainer).suspended(HttpServletRequest, HttpServletResponse) line: 104
        TomcatCometSupport.service(HttpServletRequest, HttpServletResponse) line: 106
        AtmosphereServlet.event(CometEvent) line: 480
        ApplicationFilterChain.internalDoFilterEvent(CometEvent) line: 470
        ApplicationFilterChain.doFilterEvent(CometEvent) line: 363
        StandardWrapperValve.invoke(Request, Response) line: 231
        StandardContextValve.invoke(Request, Response) line: 191
        StandardHostValve.invoke(Request, Response) line: 128
        ErrorReportValve.invoke(Request, Response) line: 102
        StandardEngineValve.invoke(Request, Response) line: 109
        CoyoteAdapter.service(Request, Response) line: 286
        Http11NioProcessor.process(NioChannel) line: 880
        Http11NioProtocol$Http11ConnectionHandler.process(NioChannel) line: 719
        NioEndpoint$SocketProcessor.run() line: 2081
        ThreadPoolExecutor$Worker.runTask(Runnable) line: 886
        ThreadPoolExecutor$Worker.run() line: 908
        Thread.run() line: 619


2. Hit the stop button on the browser. This will AGAIN invoke the AtmosphereHandler.onEvent(AtmosphereEvent) where we suspend the event and the event gets added    to the    DefaultBroadcaster.events. So the size() of  DefaultBroadcaster.events will be 2. The stacktrace for that call is :

        DefaultBroadcaster.addAtmosphereEvent(AtmosphereEventImpl) line: 140
        DefaultBroadcaster.addAtmosphereEvent(AtmosphereEvent) line: 56
        AtmosphereEventImpl.suspend(long) line: 138
        AtmosphereEventImpl.suspend() line: 128
        ChatAtmosphereHandler.onEvent(AtmosphereEvent<HttpServletRequest,HttpServletResponse>) line: 92
        TomcatCometSupport(WebContainer).action(HttpServletRequest, HttpServletResponse) line: 126
        TomcatCometSupport(WebContainer).resumed(HttpServletRequest, HttpServletResponse) line: 161       
        TomcatCometSupport.service(HttpServletRequest, HttpServletResponse) line: 140
        AtmosphereServlet.event(CometEvent) line: 480
        ApplicationFilterChain.internalDoFilterEvent(CometEvent) line: 470
        ApplicationFilterChain.doFilterEvent(CometEvent) line: 363
        StandardWrapperValve.event(Request, Response, CometEvent) line: 422
        StandardContextValve.event(Request, Response, CometEvent) line: 268
        StandardHostValve.event(Request, Response, CometEvent) line: 179
        ErrorReportValve(ValveBase).event(Request, Response, CometEvent) line: 200
        StandardEngineValve.event(Request, Response, CometEvent) line: 128
        CoyoteAdapter.event(Request, Response, SocketStatus) line: 198
        Http11NioProcessor.event(SocketStatus) line: 750
        Http11NioProtocol$Http11ConnectionHandler.event(NioChannel, SocketStatus) line: 653
        NioEndpoint$SocketProcessor.run() line: 2081
        ThreadPoolExecutor$Worker.runTask(Runnable) line: 886
        ThreadPoolExecutor$Worker.run() line: 908
        Thread.run() line: 619

3. If we hit the refresh button it does the step 1 above and now the size() of  DefaultBroadcaster.events will be 3 and I get 3 messages in the browser, since there are 3 events. Same will happen even if skip the 2nd step.

After doing the 'stop' and 'refresh' many times the size of DefaultBroadcaster.events increases, and  I get a NPE at some point of time, for some events.

java.lang.NullPointerException
        at org.apache.coyote.http11.InternalNioOutputBuffer.addToBB(InternalNioOutputBuffer.java:620)
        at org.apache.coyote.http11.InternalNioOutputBuffer.access$000(InternalNioOutputBuffer.java:46)
        at org.apache.coyote.http11.InternalNioOutputBuffer$SocketOutputBuffer.doWrite(InternalNioOutputBuffer.java:808)
        at org.apache.coyote.http11.filters.ChunkedOutputFilter.doWrite(ChunkedOutputFilter.java:124)
        at org.apache.coyote.http11.InternalNioOutputBuffer.doWrite(InternalNioOutputBuffer.java:589)
        at org.apache.coyote.Response.doWrite(Response.java:560)
        at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:353)
        at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:434)
        at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:309)
        at org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:288)
        at org.apache.catalina.connector.CoyoteWriter.flush(CoyoteWriter.java:95)
        at org.atmosphere.samples.chat.ChatAtmosphereHandler.onMessage(ChatAtmosphereHandler.java:144)
        at org.atmosphere.cpr.DefaultBroadcaster.broadcast(DefaultBroadcaster.java:117)
        at org.atmosphere.cpr.DefaultBroadcaster.broadcast(DefaultBroadcaster.java:75)
        at org.atmosphere.samples.chat.ChatAtmosphereHandler.onEvent(ChatAtmosphereHandler.java:93)
        at org.atmosphere.cpr.WebContainer.action(WebContainer.java:126)
        at org.atmosphere.cpr.WebContainer.resumed(WebContainer.java:161)
        at org.atmosphere.container.TomcatCometSupport.service(TomcatCometSupport.java:140)
        at org.atmosphere.cpr.AtmosphereServlet.event(AtmosphereServlet.java:480)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilterEvent(ApplicationFilterChain.java:470)
        at org.apache.catalina.core.ApplicationFilterChain.doFilterEvent(ApplicationFilterChain.java:363)
        at org.apache.catalina.core.StandardWrapperValve.event(StandardWrapperValve.java:422)
        at org.apache.catalina.core.StandardContextValve.event(StandardContextValve.java:268)
        at org.apache.catalina.core.StandardHostValve.event(StandardHostValve.java:179)
        at org.apache.catalina.valves.ValveBase.event(ValveBase.java:200)
        at org.apache.catalina.core.StandardEngineValve.event(StandardEngineValve.java:128)
        at org.apache.catalina.connector.CoyoteAdapter.event(CoyoteAdapter.java:198)
        at org.apache.coyote.http11.Http11NioProcessor.event(Http11NioProcessor.java:750)
        at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.event(Http11NioProtocol.java:653)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:2081)
        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:619)

So how do we make sure that the event is removed(cleanedup) when the connection is closed. How can we check whether the event is a connection closed event or a HTTP Request in the method AtmosphereHandler.onEvent(AtmosphereEvent).

Thanks,
Abey Tom
Reply | Threaded
Open this post in threaded view
|

Re: AtmosphereEvents are not getting removed even after connections are closed - Tomcat

Jeanfrancois Arcand
Salut,

apology for the delay.

abeytom wrote:
> Salut,
>
> The issue which I see is that the AtmosphereEvents are added to the
> DefaultBroadcaster.events with each refresh in the page and are not getting
> removed.

You are right this is an issue. I've filled:




>
> I think this issue kind is similar to
> a)http://n2.nabble.com/onMessage-method-is-not-called-td2743248.html
> b)http://n2.nabble.com/atmosphere-chat-on-tomcat-threw-java.lang.NullPointerException-td2677192.html
> I'm creating a new post bcos those two issues were fixed and I'm getting
> issues with the latest code.

The issue is I need to implement a way to detect that the remote client
has closed the connection. It is simple to do with Tomcat/Grizzly, but
more complicated with other container. I will work on something for you
today.


>
> I'm working with the sample application
> https://www.dev.java.net/svn/atmosphere/trunk/atmosphere/samples/chat in
> apache-tomcat-6.0.18.I built latest the atmosphere code from the trunk.
>
> To reproduce the issue please follow the below steps.
> 1. Hit the url http://<ip>/atmosphere-chat/index.html(IE, Firefox) - This
> will invoke the AtmosphereHandler.onEvent(AtmosphereEvent) where we suspend
> the event and the event gets added to the DefaultBroadcaster.events. So the
> size() of  DefaultBroadcaster.events will be 1. The stacktrace for that call
> is :
>
> DefaultBroadcaster.addAtmosphereEvent(AtmosphereEventImpl) line: 140
> DefaultBroadcaster.addAtmosphereEvent(AtmosphereEvent) line: 56
> AtmosphereEventImpl.suspend(long) line: 138
> AtmosphereEventImpl.suspend() line: 128
>
> ChatAtmosphereHandler.onEvent(AtmosphereEvent<HttpServletRequest,HttpServletResponse>)
> line: 92
> TomcatCometSupport(WebContainer).action(HttpServletRequest,
> HttpServletResponse) line: 126
> TomcatCometSupport(WebContainer).suspended(HttpServletRequest,
> HttpServletResponse) line: 104
> TomcatCometSupport.service(HttpServletRequest, HttpServletResponse) line:
> 106
> AtmosphereServlet.event(CometEvent) line: 480
> ApplicationFilterChain.internalDoFilterEvent(CometEvent) line: 470
> ApplicationFilterChain.doFilterEvent(CometEvent) line: 363
> StandardWrapperValve.invoke(Request, Response) line: 231
> StandardContextValve.invoke(Request, Response) line: 191
> StandardHostValve.invoke(Request, Response) line: 128
> ErrorReportValve.invoke(Request, Response) line: 102
> StandardEngineValve.invoke(Request, Response) line: 109
> CoyoteAdapter.service(Request, Response) line: 286
> Http11NioProcessor.process(NioChannel) line: 880
> Http11NioProtocol$Http11ConnectionHandler.process(NioChannel) line: 719
> NioEndpoint$SocketProcessor.run() line: 2081
> ThreadPoolExecutor$Worker.runTask(Runnable) line: 886
> ThreadPoolExecutor$Worker.run() line: 908
> Thread.run() line: 619
>
>
> 2. Hit the stop button on the browser. This will AGAIN invoke the
> AtmosphereHandler.onEvent(AtmosphereEvent) where we suspend the event and
> the event gets added    to the    DefaultBroadcaster.events. So the size()
> of  DefaultBroadcaster.events will be 2. The stacktrace for that call is :
>
> DefaultBroadcaster.addAtmosphereEvent(AtmosphereEventImpl) line: 140
> DefaultBroadcaster.addAtmosphereEvent(AtmosphereEvent) line: 56
> AtmosphereEventImpl.suspend(long) line: 138
> AtmosphereEventImpl.suspend() line: 128
>
> ChatAtmosphereHandler.onEvent(AtmosphereEvent<HttpServletRequest,HttpServletResponse>)
> line: 92
> TomcatCometSupport(WebContainer).action(HttpServletRequest,
> HttpServletResponse) line: 126
> TomcatCometSupport(WebContainer).resumed(HttpServletRequest,
> HttpServletResponse) line: 161
> TomcatCometSupport.service(HttpServletRequest, HttpServletResponse) line:
> 140
> AtmosphereServlet.event(CometEvent) line: 480
> ApplicationFilterChain.internalDoFilterEvent(CometEvent) line: 470
> ApplicationFilterChain.doFilterEvent(CometEvent) line: 363
> StandardWrapperValve.event(Request, Response, CometEvent) line: 422
> StandardContextValve.event(Request, Response, CometEvent) line: 268
> StandardHostValve.event(Request, Response, CometEvent) line: 179
> ErrorReportValve(ValveBase).event(Request, Response, CometEvent) line: 200
> StandardEngineValve.event(Request, Response, CometEvent) line: 128
> CoyoteAdapter.event(Request, Response, SocketStatus) line: 198
> Http11NioProcessor.event(SocketStatus) line: 750
> Http11NioProtocol$Http11ConnectionHandler.event(NioChannel, SocketStatus)
> line: 653
> NioEndpoint$SocketProcessor.run() line: 2081
> ThreadPoolExecutor$Worker.runTask(Runnable) line: 886
> ThreadPoolExecutor$Worker.run() line: 908
> Thread.run() line: 619
>
> 3. If we hit the refresh button it does the step 1 above and now the size()
> of  DefaultBroadcaster.events will be 3 and I get 3 messages in the browser,
> since there are 3 events. Same will happen even if skip the 2nd step.
>
> After doing the 'stop' and 'refresh' many times the size of
> DefaultBroadcaster.events increases, and  I get a NPE at some point of time,
> for some events.
>
> java.lang.NullPointerException
>         at
> org.apache.coyote.http11.InternalNioOutputBuffer.addToBB(InternalNioOutputBuffer.java:620)
>         at
> org.apache.coyote.http11.InternalNioOutputBuffer.access$000(InternalNioOutputBuffer.java:46)
>         at
> org.apache.coyote.http11.InternalNioOutputBuffer$SocketOutputBuffer.doWrite(InternalNioOutputBuffer.java:808)
>         at
> org.apache.coyote.http11.filters.ChunkedOutputFilter.doWrite(ChunkedOutputFilter.java:124)
>         at
> org.apache.coyote.http11.InternalNioOutputBuffer.doWrite(InternalNioOutputBuffer.java:589)
>         at org.apache.coyote.Response.doWrite(Response.java:560)
>         at
> org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:353)
>         at
> org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:434)
>         at
> org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:309)
>         at
> org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:288)
>         at
> org.apache.catalina.connector.CoyoteWriter.flush(CoyoteWriter.java:95)
>         at
> org.atmosphere.samples.chat.ChatAtmosphereHandler.onMessage(ChatAtmosphereHandler.java:144)
>         at
> org.atmosphere.cpr.DefaultBroadcaster.broadcast(DefaultBroadcaster.java:117)
>         at
> org.atmosphere.cpr.DefaultBroadcaster.broadcast(DefaultBroadcaster.java:75)
>         at
> org.atmosphere.samples.chat.ChatAtmosphereHandler.onEvent(ChatAtmosphereHandler.java:93)
>         at org.atmosphere.cpr.WebContainer.action(WebContainer.java:126)
>         at org.atmosphere.cpr.WebContainer.resumed(WebContainer.java:161)
>         at
> org.atmosphere.container.TomcatCometSupport.service(TomcatCometSupport.java:140)
>         at
> org.atmosphere.cpr.AtmosphereServlet.event(AtmosphereServlet.java:480)
>         at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilterEvent(ApplicationFilterChain.java:470)
>         at
> org.apache.catalina.core.ApplicationFilterChain.doFilterEvent(ApplicationFilterChain.java:363)
>         at
> org.apache.catalina.core.StandardWrapperValve.event(StandardWrapperValve.java:422)
>         at
> org.apache.catalina.core.StandardContextValve.event(StandardContextValve.java:268)
>         at
> org.apache.catalina.core.StandardHostValve.event(StandardHostValve.java:179)
>         at org.apache.catalina.valves.ValveBase.event(ValveBase.java:200)
>         at
> org.apache.catalina.core.StandardEngineValve.event(StandardEngineValve.java:128)
>         at
> org.apache.catalina.connector.CoyoteAdapter.event(CoyoteAdapter.java:198)
>         at
> org.apache.coyote.http11.Http11NioProcessor.event(Http11NioProcessor.java:750)
>         at
> org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.event(Http11NioProtocol.java:653)
>         at
> org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:2081)
>         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:619)
>
> So how do we make sure that the event is removed(cleanedup) when the
> connection is closed. How can we check whether the event is a connection
> closed event or a HTTP Request in the method
> AtmosphereHandler.onEvent(AtmosphereEvent).

Working on it. THANKS!!!!

-- Jeanfrancois




>
> Thanks,
> Abey Tom

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: AtmosphereEvents are not getting removed even after connections are closed - Tomcat

abeytom
Hi Jean

Thanks again for the super fast responses/fixes.. Two more concerns. I checked out the latest workspace before doing this test.


===========================Issue 1=============================
I'm facing some issues with the objects not getting recycled properly.In DefaultBroadcaster.removeAtmosphereEvent() is bieng invoked with a different event as an argument.  I added some LOG statements in the following methods of the class DefaultBroadcaster.

   
    public void broadcast(Object msg) {
    LoggerUtils.getLogger().log(Level.INFO, "\tBroadcasting to Events - "+events);
        for (AtmosphereEventImpl event : events) {...method Body...}
    }


    public boolean addAtmosphereEvent(AtmosphereEventImpl event) {
    boolean offer = events.offer(event);
    LoggerUtils.getLogger().log(Level.INFO, "\tAdded the Atmospheric Event; "+event+ "\n\tTotal Size "+events.size()+" - "+events);
        return offer;
    }

       
    public boolean removeAtmosphereEvent(AtmosphereEventImpl event) {
        boolean remove = events.remove(event);
        LoggerUtils.getLogger().log(Level.INFO, "\tRemoved the Atmospheric Event; "+event+"\n\tTotal Size "+events.size()+" - "+events);
        return remove;
    }


So this is how it happens. I'm adding my comments in between the log statements. Please look at the objectId getting printed out.

****************** I hit the index.html 1 event gets created.

May 13, 2009 4:10:11 PM org.atmosphere.cpr.DefaultBroadcaster addAtmosphereEvent
INFO:   Added the Atmospheric Event; org.atmosphere.cpr.AtmosphereEventImpl@a0c486
        Total Size 1 - [org.atmosphere.cpr.AtmosphereEventImpl@a0c486]
May 13, 2009 4:10:11 PM org.atmosphere.cpr.DefaultBroadcaster broadcast
INFO:   Broadcasting to Events - [org.atmosphere.cpr.AtmosphereEventImpl@a0c486]

************ I type my name to Login. The message is broadcasted.

May 13, 2009 4:10:23 PM org.atmosphere.cpr.DefaultBroadcaster broadcast
INFO:   Broadcasting to Events - [org.atmosphere.cpr.AtmosphereEventImpl@a0c486]

****************** I click on the stop button on the browser. removeAtmosphereEvent gets called with some other event as argument. The original event is still not removed from collection.

May 13, 2009 4:10:30 PM org.atmosphere.cpr.DefaultBroadcaster removeAtmosphereEvent
INFO:   Removed the Atmospheric Event; org.atmosphere.cpr.AtmosphereEventImpl@6030f9
        Total Size 1 - [org.atmosphere.cpr.AtmosphereEventImpl@a0c486]

**************** I try to send a message. The messages is being broadcasted to the original event which was closed(which was supposed to be removed). So NPE.

May 13, 2009 4:10:43 PM org.atmosphere.cpr.DefaultBroadcaster broadcast
INFO:   Broadcasting to Events - [org.atmosphere.cpr.AtmosphereEventImpl@a0c486]
java.lang.NullPointerException
        at org.apache.coyote.http11.InternalNioOutputBuffer.addToBB(InternalNioOutputBuffer.java:620)
        at org.apache.coyote.http11.InternalNioOutputBuffer.commit(InternalNioOutputBuffer.java:611)
        ....
 

========================= Issue 2========================

Also In the Sample application servlet, ChatAtmosphereHandler.onMessage(..) This follwing piece of code will lead to an infinite loop.

        if (event.isCancelled()){
           event.getBroadcaster().broadcast(req.getSession().getAttribute("name").toString() + " has left");
        }

Please see the abstract of the stack trace for the same.

        ChatAtmosphereHandler.onMessage(AtmosphereEvent<HttpServletRequest,HttpServletResponse>) line: 139
        DefaultBroadcaster.broadcast(AtmosphereEvent) line: 117
        DefaultBroadcaster.broadcast(Object) line: 75
        ChatAtmosphereHandler.onMessage(AtmosphereEvent<HttpServletRequest,HttpServletResponse>) line: 139
        DefaultBroadcaster.broadcast(AtmosphereEvent) line: 117
        DefaultBroadcaster.broadcast(Object) line: 75
        ChatAtmosphereHandler.onMessage(AtmosphereEvent<HttpServletRequest,HttpServletResponse>) line: 139
        DefaultBroadcaster.broadcast(AtmosphereEvent) line: 117
        DefaultBroadcaster.broadcast(Object) line: 75
        ChatAtmosphereHandler.onMessage(AtmosphereEvent<HttpServletRequest,HttpServletResponse>) line: 139
        DefaultBroadcaster.broadcast(AtmosphereEvent) line: 117
        DefaultBroadcaster.broadcast(Object) line: 75
        ChatAtmosphereHandler.onEvent(AtmosphereEvent<HttpServletRequest,HttpServletResponse>) line: 93
        TomcatCometSupport(WebContainer).action(HttpServletRequest, HttpServletResponse) line: 127
        TomcatCometSupport(WebContainer).suspended(HttpServletRequest, HttpServletResponse) line: 105
        TomcatCometSupport.service(HttpServletRequest, HttpServletResponse) line: 106
        AtmosphereServlet.event(CometEvent) line: 480
        ApplicationFilterChain.internalDoFilterEvent(CometEvent) line: 470


Please let me know if you have any question.

Thanks Again
Abey Tom
Reply | Threaded
Open this post in threaded view
|

Re: AtmosphereEvents are not getting removed even after connections are closed - Tomcat

Jeanfrancois Arcand
Salut,

abeytom wrote:
> Hi Jean
>
> Thanks again for the super fast responses/fixes.. Two more concerns. I
> checked out the latest workspace before doing this test.

Thanks! Yes readibg the description below there is clearly an issue.
What I need to understand is why Tomcat isn't sending the proper Req/Res
object when the page is refreshed. Looking at it.

Thanks!!

-- Jeanfrancois

>
> ===========================Issue 1=============================
> I'm facing some issues with the objects not getting recycled properly.In
> DefaultBroadcaster.removeAtmosphereEvent() is bieng invoked with a different
> event as an argument.  I added some LOG statements in the following methods
> of the class DefaultBroadcaster.
>
>    
>     public void broadcast(Object msg) {
>     LoggerUtils.getLogger().log(Level.INFO, "\tBroadcasting to Events -
> "+events);
>         for (AtmosphereEventImpl event : events) {...method Body...}
>     }
>
>
>     public boolean addAtmosphereEvent(AtmosphereEventImpl event) {
>     boolean offer = events.offer(event);
>     LoggerUtils.getLogger().log(Level.INFO, "\tAdded the Atmospheric
> Event; "+event+ "\n\tTotal Size "+events.size()+" - "+events);
> return offer;
>     }
>
>        
>     public boolean removeAtmosphereEvent(AtmosphereEventImpl event) {
>         boolean remove = events.remove(event);
>         LoggerUtils.getLogger().log(Level.INFO, "\tRemoved the Atmospheric
> Event; "+event+"\n\tTotal Size "+events.size()+" - "+events);
>         return remove;
>     }
>
>
> So this is how it happens. I'm adding my comments in between the log
> statements. Please look at the objectId getting printed out.
>
> ****************** I hit the index.html 1 event gets created.
>
> May 13, 2009 4:10:11 PM org.atmosphere.cpr.DefaultBroadcaster
> addAtmosphereEvent
> INFO:   Added the Atmospheric Event;
> org.atmosphere.cpr.AtmosphereEventImpl@a0c486
>         Total Size 1 - [org.atmosphere.cpr.AtmosphereEventImpl@a0c486]
> May 13, 2009 4:10:11 PM org.atmosphere.cpr.DefaultBroadcaster broadcast
> INFO:   Broadcasting to Events -
> [org.atmosphere.cpr.AtmosphereEventImpl@a0c486]
>
> ************ I type my name to Login. The message is broadcasted.
>
> May 13, 2009 4:10:23 PM org.atmosphere.cpr.DefaultBroadcaster broadcast
> INFO:   Broadcasting to Events -
> [org.atmosphere.cpr.AtmosphereEventImpl@a0c486]
>
> ****************** I click on the stop button on the browser.
> removeAtmosphereEvent gets called with some other event as argument. The
> original event is still not removed from collection.
>
> May 13, 2009 4:10:30 PM org.atmosphere.cpr.DefaultBroadcaster
> removeAtmosphereEvent
> INFO:   Removed the Atmospheric Event;
> org.atmosphere.cpr.AtmosphereEventImpl@6030f9
>         Total Size 1 - [org.atmosphere.cpr.AtmosphereEventImpl@a0c486]
>
> **************** I try to send a message. The messages is being broadcasted
> to the original event which was closed(which was supposed to be removed). So
> NPE.
>
> May 13, 2009 4:10:43 PM org.atmosphere.cpr.DefaultBroadcaster broadcast
> INFO:   Broadcasting to Events -
> [org.atmosphere.cpr.AtmosphereEventImpl@a0c486]
> java.lang.NullPointerException
>         at
> org.apache.coyote.http11.InternalNioOutputBuffer.addToBB(InternalNioOutputBuffer.java:620)
>         at
> org.apache.coyote.http11.InternalNioOutputBuffer.commit(InternalNioOutputBuffer.java:611)
> ....
>  
> ========================= Issue 2========================
>
> Also In the Sample application servlet, ChatAtmosphereHandler.onMessage(..)
> This follwing piece of code will lead to an infinite loop.
>
> if (event.isCancelled()){
>          
> event.getBroadcaster().broadcast(req.getSession().getAttribute("name").toString()
> + " has left");
> }
>
> Please see the abstract of the stack trace for the same.
>
>
> ChatAtmosphereHandler.onMessage(AtmosphereEvent<HttpServletRequest,HttpServletResponse>)
> line: 139
> DefaultBroadcaster.broadcast(AtmosphereEvent) line: 117
> DefaultBroadcaster.broadcast(Object) line: 75
>
> ChatAtmosphereHandler.onMessage(AtmosphereEvent<HttpServletRequest,HttpServletResponse>)
> line: 139
> DefaultBroadcaster.broadcast(AtmosphereEvent) line: 117
> DefaultBroadcaster.broadcast(Object) line: 75
>
> ChatAtmosphereHandler.onMessage(AtmosphereEvent<HttpServletRequest,HttpServletResponse>)
> line: 139
> DefaultBroadcaster.broadcast(AtmosphereEvent) line: 117
> DefaultBroadcaster.broadcast(Object) line: 75
>
> ChatAtmosphereHandler.onMessage(AtmosphereEvent<HttpServletRequest,HttpServletResponse>)
> line: 139
> DefaultBroadcaster.broadcast(AtmosphereEvent) line: 117
> DefaultBroadcaster.broadcast(Object) line: 75
>
> ChatAtmosphereHandler.onEvent(AtmosphereEvent<HttpServletRequest,HttpServletResponse>)
> line: 93
> TomcatCometSupport(WebContainer).action(HttpServletRequest,
> HttpServletResponse) line: 127
> TomcatCometSupport(WebContainer).suspended(HttpServletRequest,
> HttpServletResponse) line: 105
> TomcatCometSupport.service(HttpServletRequest, HttpServletResponse) line:
> 106
> AtmosphereServlet.event(CometEvent) line: 480
> ApplicationFilterChain.internalDoFilterEvent(CometEvent) line: 470
>
>
> Please let me know if you have any question.
>
> Thanks Again
> Abey Tom

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

(fixed )Re: AtmosphereEvents are not getting removed even after connections are closed - Tomcat

Jeanfrancois Arcand
Salut,

thanks for you analysis (sorry for the delay, java.net was down), this
is now fixed. I'm attaching the jar file. I've also updated the Chat
example to properly log out when some leave.

Continue your feedback!

Thanks!

-- Jeanfrancois

Jeanfrancois Arcand wrote:

> Salut,
>
> abeytom wrote:
>> Hi Jean
>> Thanks again for the super fast responses/fixes.. Two more concerns. I
>> checked out the latest workspace before doing this test.
>
> Thanks! Yes readibg the description below there is clearly an issue.
> What I need to understand is why Tomcat isn't sending the proper Req/Res
> object when the page is refreshed. Looking at it.
>
> Thanks!!
>
> -- Jeanfrancois
>
>>
>> ===========================Issue 1=============================
>> I'm facing some issues with the objects not getting recycled properly.In
>> DefaultBroadcaster.removeAtmosphereEvent() is bieng invoked with a
>> different
>> event as an argument.  I added some LOG statements in the following
>> methods
>> of the class DefaultBroadcaster.
>>
>>         public void broadcast(Object msg) {
>>             LoggerUtils.getLogger().log(Level.INFO, "\tBroadcasting to
>> Events -
>> "+events);
>>         for (AtmosphereEventImpl event : events) {...method Body...}
>>     }
>>
>>
>>     public boolean addAtmosphereEvent(AtmosphereEventImpl event) {
>>             boolean offer = events.offer(event);
>>             LoggerUtils.getLogger().log(Level.INFO, "\tAdded the
>> Atmospheric
>> Event; "+event+ "\n\tTotal Size "+events.size()+" - "+events);
>>     return offer;
>>     }
>>
>>            public boolean removeAtmosphereEvent(AtmosphereEventImpl
>> event) {
>>         boolean remove = events.remove(event);
>>         LoggerUtils.getLogger().log(Level.INFO, "\tRemoved the
>> Atmospheric
>> Event; "+event+"\n\tTotal Size "+events.size()+" - "+events);
>>         return remove;
>>     }
>>
>>
>> So this is how it happens. I'm adding my comments in between the log
>> statements. Please look at the objectId getting printed out.
>>
>> ****************** I hit the index.html 1 event gets created.
>>
>> May 13, 2009 4:10:11 PM org.atmosphere.cpr.DefaultBroadcaster
>> addAtmosphereEvent
>> INFO:   Added the Atmospheric Event;
>> org.atmosphere.cpr.AtmosphereEventImpl@a0c486
>>         Total Size 1 - [org.atmosphere.cpr.AtmosphereEventImpl@a0c486]
>> May 13, 2009 4:10:11 PM org.atmosphere.cpr.DefaultBroadcaster broadcast
>> INFO:   Broadcasting to Events -
>> [org.atmosphere.cpr.AtmosphereEventImpl@a0c486]
>>
>> ************ I type my name to Login. The message is broadcasted.
>>
>> May 13, 2009 4:10:23 PM org.atmosphere.cpr.DefaultBroadcaster broadcast
>> INFO:   Broadcasting to Events -
>> [org.atmosphere.cpr.AtmosphereEventImpl@a0c486]
>>
>> ****************** I click on the stop button on the browser.
>> removeAtmosphereEvent gets called with some other event as argument. The
>> original event is still not removed from collection.
>>
>> May 13, 2009 4:10:30 PM org.atmosphere.cpr.DefaultBroadcaster
>> removeAtmosphereEvent
>> INFO:   Removed the Atmospheric Event;
>> org.atmosphere.cpr.AtmosphereEventImpl@6030f9
>>         Total Size 1 - [org.atmosphere.cpr.AtmosphereEventImpl@a0c486]
>>
>> **************** I try to send a message. The messages is being
>> broadcasted
>> to the original event which was closed(which was supposed to be
>> removed). So
>> NPE.
>>
>> May 13, 2009 4:10:43 PM org.atmosphere.cpr.DefaultBroadcaster broadcast
>> INFO:   Broadcasting to Events -
>> [org.atmosphere.cpr.AtmosphereEventImpl@a0c486]
>> java.lang.NullPointerException
>>         at
>> org.apache.coyote.http11.InternalNioOutputBuffer.addToBB(InternalNioOutputBuffer.java:620)
>>
>>         at
>> org.apache.coyote.http11.InternalNioOutputBuffer.commit(InternalNioOutputBuffer.java:611)
>>
>>     ....
>>  
>> ========================= Issue 2========================
>>
>> Also In the Sample application servlet,
>> ChatAtmosphereHandler.onMessage(..)
>> This follwing piece of code will lead to an infinite loop.
>>
>>     if (event.isCancelled()){
>>          
>> event.getBroadcaster().broadcast(req.getSession().getAttribute("name").toString()
>>
>> + " has left");
>>     }
>>
>> Please see the abstract of the stack trace for the same.
>>
>>
>> ChatAtmosphereHandler.onMessage(AtmosphereEvent<HttpServletRequest,HttpServletResponse>)
>>
>> line: 139  
>>     DefaultBroadcaster.broadcast(AtmosphereEvent) line: 117  
>>     DefaultBroadcaster.broadcast(Object) line: 75  
>>
>> ChatAtmosphereHandler.onMessage(AtmosphereEvent<HttpServletRequest,HttpServletResponse>)
>>
>> line: 139  
>>     DefaultBroadcaster.broadcast(AtmosphereEvent) line: 117  
>>     DefaultBroadcaster.broadcast(Object) line: 75  
>>
>> ChatAtmosphereHandler.onMessage(AtmosphereEvent<HttpServletRequest,HttpServletResponse>)
>>
>> line: 139  
>>     DefaultBroadcaster.broadcast(AtmosphereEvent) line: 117  
>>     DefaultBroadcaster.broadcast(Object) line: 75  
>>
>> ChatAtmosphereHandler.onMessage(AtmosphereEvent<HttpServletRequest,HttpServletResponse>)
>>
>> line: 139  
>>     DefaultBroadcaster.broadcast(AtmosphereEvent) line: 117  
>>     DefaultBroadcaster.broadcast(Object) line: 75  
>>
>> ChatAtmosphereHandler.onEvent(AtmosphereEvent<HttpServletRequest,HttpServletResponse>)
>>
>> line: 93  
>>     TomcatCometSupport(WebContainer).action(HttpServletRequest,
>> HttpServletResponse) line: 127  
>>     TomcatCometSupport(WebContainer).suspended(HttpServletRequest,
>> HttpServletResponse) line: 105  
>>     TomcatCometSupport.service(HttpServletRequest,
>> HttpServletResponse) line:
>> 106  
>>     AtmosphereServlet.event(CometEvent) line: 480  
>>     ApplicationFilterChain.internalDoFilterEvent(CometEvent) line: 470  
>>
>>
>> Please let me know if you have any question.
>>
>> Thanks Again
>> Abey Tom
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

atmosphere-portable-runtime-0.2-SNAPSHOT.jar (90K) Download Attachment