Actually, removeComentHandler -> resumeCometHandler will not work either.
The problem is that 2nd client executes this code:
System.out.println("Already registred remove the client
from engine");
CometEngine.getEngine().unregister(contextPath);
which causes CometHandler.onTerminate() call for the 1st client, but at
that time CometContext is null (2nd client removed it), so
private void removeThisFromContext() throws IOException {
if (response.hashCode() == agentId) {
response.getWriter().close();
CometContext context =
CometEngine.getEngine().getCometContext(contextPath);
// context.removeCometHandler(this);
context.resumeCometHandler(this);
CometEngine.getEngine().unregister(contextPath);
System.out.println("Closing Agent connection as result");
// context.removeCometHandler(this);
}
}
throws NPE.
I remade your code a bit (attached), which seems to work.
WBR,
Alexey.
On 02/13/2012 01:45 PM, Oleksiy Stashok wrote:
> Hi Alex,
>
> my fault, I had stopped first client before ran 2nd one :)
> Anyway, if you replace removeCometHandler with resumeCometHandler it
> should work.
>
> Thanks.
>
> WBR,
> Alexey.
>
> On 02/13/2012 12:14 PM, Alex Kalnitski wrote:
>>
>> Alexey ;
>>
>> You should get something like this in the server log
>>
>> (first client attempt)
>>
>> INFO: SERVER: Do POST
>>
>> INFO: Got Post request from ip 127.0.0.1
>>
>> INFO: SERVER: Session id = 668f45d11e44f076d61389d42633
>>
>> INFO: SERVER: Agent0
>>
>> INFO: {client=[Ljava.lang.String;@269101}
>>
>> INFO: SERVER: null
>>
>> INFO: client not exit , register client
>>
>> INFO: Connected from ip 127.0.0.1
>>
>> (first client connected/ registered in the comet engine)
>>
>> (second client try to register )
>>
>> INFO: SERVER: Do POST
>>
>> INFO: Got Post request from ip 127.0.0.1
>>
>> INFO: SERVER: Session id = 6691154e0cdc9015808698f986b5
>>
>> INFO: SERVER: Agent0
>>
>> INFO: {client=[Ljava.lang.String;@e671a1}
>>
>> INFO: SERVER: null
>>
>> INFO: client not exit , register client
>>
>> INFO: Already registred remove the client from engine
>>
>> INFO: Closing Agent connection as result
>>
>> WBR
>>
>> Alex Kalnitski
>>
>> Lead R&D Server Side
>>
>> AT&T | Interwise
>>
>> *From:*Alex Kalnitski
>> *Sent:* Monday, February 13, 2012 1:09 PM
>> *To:* 'Oleksiy Stashok'
>> *Cc:* users_at_grizzly.java.net
>> *Subject:* RE: FW: Glassfish issue
>>
>> Hi Alexey,
>>
>> Thanks for the quick post,
>>
>> According to the log that you have attached I don't see second client
>> connection try (which actually cause to the issue), I only see one
>> request, please correct me if I am wrong .
>>
>> I just want to clarify on how to reproduce this issue ,
>>
>> After the server side is running, you will need to start client
>> twice in IDE (without stopping the first run)
>>
>> Such action will start first client and put It to blocking state,
>> when second client will try to create connection to the server,
>> server will try to remove first client and the phenomena should be
>> recreated .
>>
>> I use GlassFish open source 3.1.1 build 12 and java jdk1.6.0_26
>>
>> I am very appreciating you help !
>>
>> Thanks a lot in advance.
>>
>> Alex Kalnitski
>>
>> Lead R&D Server Side
>>
>> AT&T | Interwise
>>
>> *From:*Oleksiy Stashok [mailto:oleksiy.stashok_at_oracle.com]
>> *Sent:* Monday, February 13, 2012 12:36 PM
>> *To:* Alex Kalnitski
>> *Cc:* users_at_grizzly.java.net <mailto:users_at_grizzly.java.net>
>> *Subject:* Re: FW: Glassfish issue
>>
>> Hi Alex,
>>
>> unfortunately I'm not able to reproduce the 100% CPU utilization, in
>> the GF server.log I see the output [1] for each client run. Is it
>> correct?
>> Just one thing I can suggest to try, instead of
>> context.removeCometHandler(this), call context.resumeCometHandler(this)
>>
>> Thanks.
>>
>> WBR,
>> Alexey.
>>
>>
>> [1]
>> [#|2012-02-13T11:29:19.145+0100|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=24;_ThreadName=Thread-2;|SERVER:
>> Do POST |#]
>>
>> [#|2012-02-13T11:29:19.146+0100|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=24;_ThreadName=Thread-2;|Got
>> Post request from ip 127.0.0.1|#]
>>
>> [#|2012-02-13T11:29:19.146+0100|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=24;_ThreadName=Thread-2;|SERVER:
>> Session id = 6426caa9450f342ea80106ed7a38|#]
>>
>> [#|2012-02-13T11:29:19.146+0100|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=24;_ThreadName=Thread-2;|SERVER:
>> Agent0|#]
>>
>> [#|2012-02-13T11:29:19.147+0100|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=24;_ThreadName=Thread-2;|{client=[Ljava.lang.String;@54e94480}|#]
>>
>> [#|2012-02-13T11:29:19.147+0100|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=24;_ThreadName=Thread-2;|SERVER:
>> null|#]
>>
>> [#|2012-02-13T11:29:19.147+0100|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=24;_ThreadName=Thread-2;|client
>> not exit , register client|#]
>>
>> [#|2012-02-13T11:29:19.148+0100|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=24;_ThreadName=Thread-2;|Connected
>> from ip 127.0.0.1|#]
>>
>> [#|2012-02-13T11:29:41.665+0100|INFO|glassfish3.1.2|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=13;_ThreadName=Thread-2;|Closing
>> Agent connection as result|#]
>>
>>
>> On 02/12/2012 12:26 PM, Alex Kalnitski wrote:
>>
>> Hi Alexey;
>>
>> I have created two classes to reproduce this phenomenon of High CPU
>> utilization .
>>
>> One class is Agent -- Client side and another class is Server side
>> CometServlet .
>>
>> To reproduce this situation you will need to run AgentLoader twice ,
>> such way it simulates the not properly disconnected client and
>> actually creates the CPU high utilization .
>>
>> Please let me know if it was successful and where maybe I am wrong
>>
>> WBR
>>
>> Alex Kalnitski
>>
>> Lead R&D Server Side
>>
>> AT&T | Interwise
>>
>> *From:*Oleksiy Stashok [mailto:oleksiy.stashok_at_oracle.com]
>> *Sent:* Wednesday, January 25, 2012 5:33 PM
>> *To:* Alex Kalnitski
>> *Cc:* users_at_grizzly.java.net <mailto:users_at_grizzly.java.net>
>> *Subject:* Re: FW: Glassfish issue
>>
>> Can you pls. create a testcase for this issue, so we can reproduce it?
>>
>> Thanks.
>>
>> WBR,
>> Alexey.
>>
>> On 01/25/2012 04:26 PM, Alex Kalnitski wrote:
>>
>> Thanks for the quick response
>>
>> Our use case:
>>
>> We are using comet to process mobile messages and in some corner
>> cases we are getting after the issue occurs 100% CPU utilization .
>>
>> 1.Each mobile register to the Context with unique name
>>
>> 2.When mobile disconnects from server the connection released
>> normally by utilizing the onTerminate() and removed from the engine .
>>
>> 3.When mobile device is shutdown and there is no normal device
>> disconnection process, no event is received at the server side and
>> methods onTerminateand onInterruptare not invoked so the mobile
>> remains registered in the CometEngine.
>>
>> 4.When mobile try to reconnect we find out that the same context
>> name already exist in the system so need to removed it manually by
>> invoking CometEngine./getEngine/().unregister(contextPath);
>>
>> 5.Executing this action cause CPU jump to 100% and stay there until
>> the java process is killed .
>>
>> Is this issue is known?
>>
>> Please advice, maybe I am using it in wrong way , I also saw that in
>> new version some methods are deprecated, but I don't understand how
>> to integrated it to the glassfish server .
>>
>> WBR
>>
>> Alex Kalnitski
>>
>> Lead R&D Server Side
>>
>> AT&T | Interwise
>>
>> *From:*Oleksiy Stashok [mailto:oleksiy.stashok_at_oracle.com]
>> *Sent:* Wednesday, January 25, 2012 4:00 PM
>> *To:* Alex Kalnitski
>> *Cc:* users_at_grizzly.java.net <mailto:users_at_grizzly.java.net>
>> *Subject:* Re: FW: Glassfish issue
>>
>> Hi Alex,
>>
>> you can send issue details to users_at_grizzly.java.net
>> <mailto:users_at_grizzly.java.net> (CC'ed) and we'll try to help.
>>
>> Thanks.
>>
>> WBR,
>> Alexey.
>>
>> On 01/25/2012 02:55 PM, Alex Kalnitski wrote:
>>
>> Hi ;
>>
>> We are using an Glassfish server open source edition v3.1.1 for our
>> benchmarking with Comet technology and we have something that looks
>> like a bug .
>>
>> Please advice what should I do next and where should I go further .
>>
>> BR
>>
>> Alex
>>
>> Lead R&D
>>
>> AT&T Interties .
>>
>