atmosphere-samples icon indicating copy to clipboard operation
atmosphere-samples copied to clipboard

Long-polling: Broadcast to resource in quick succession - resource cannot be acquired

Open LeeDavidMalcolm opened this issue 7 years ago • 0 comments

Originally raised in google group: https://groups.google.com/forum/#!topic/atmosphere-framework/-v9SFkGuW3I

Hi,

Thanks in advance for the help. Hopefully this is the right place for this.

The setup is long-polling on IBM websphere 8.5.5.4 with atmosphere version 2.4.2. When I send multiple messages to be broadcast (say 25 one after another) or occasionally a freak occurrence where two messages are to be broadcast immediately one after the other the resource cannot be acquired.

Using a class with @ManagedService(path = "/broadcast") to handle connections and create an AtmosphereSession for each connection

I am then using AtmosphereSession objects to acquire the resource: AtmosphereResource resource = session.tryAcquire(5);

And then get the broadcaster from the resource: Broadcaster broadcaster = resource.getBroadcaster();

But the first call fails. If I increase the timeout it can reduce the problem but can take up to 15 seconds to get the resource or still fail.

My atmosphere configuration is as follows:

<dependency>
            <groupId>org.atmosphere</groupId>
            <artifactId>atmosphere-runtime</artifactId>
</dependency>


<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0"
 xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
 <display-name>${serviceName}-${serviceVersion}</display-name>
 <servlet>
        <description>AtmosphereServlet</description>
        <servlet-name>AtmosphereServlet</servlet-name>
        <servlet-class>org.atmosphere.cpr.AtmosphereServlet</servlet-class>
        <init-param>
            <param-name>org.atmosphere.cpr.packages</param-name>
            <param-value>com.test.project.broadcast.atmosphere</param-value>
        </init-param>
        <init-param>
 <param-name>org.atmosphere.cpr.dropAccessControlAllowOriginHeader</param-name>
 <param-value>false</param-value>
 </init-param>
        <init-param>
            <param-name>org.atmosphere.cpr.AtmosphereInterceptor.disableDefaults</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>org.atmosphere.cpr.AtmosphereInterceptor</param-name>
          <param-value>org.atmosphere.interceptor.HeartbeatInterceptor, org.atmosphere.interceptor.PaddingAtmosphereInterceptor , org.atmosphere.interceptor.SSEAtmosphereInterceptor, org.atmosphere.interceptor.CacheHeadersInterceptor, org.atmosphere.interceptor.AndroidAtmosphereInterceptor, org.atmosphere.interceptor.JSONPAtmosphereInterceptor, org.atmosphere.interceptor.JavaScriptProtocol, org.atmosphere.interceptor.WebSocketMessageSuspendInterceptor, org.atmosphere.interceptor.OnDisconnectInterceptor, org.atmosphere.interceptor.IdleResourceInterceptor</param-value>
 </init-param>
 <init-param>
 <param-name>org.atmosphere.cpr.broadcasterLifeCyclePolicy</param-name>
 <param-value>IDLE_DESTROY</param-value>
 </init-param>
 <init-param>
            <param-name>org.atmosphere.cpr.broadcaster.shareableThreadPool</param-name>
            <param-value>true</param-value>
        </init-param>
         <init-param>
            <param-name>org.atmosphere.cpr.broadcaster.maxProcessingThreads</param-name>
            <param-value>10</param-value>
        </init-param>
         <init-param>
            <param-name>org.atmosphere.cpr.broadcaster.maxAsyncWriteThreads</param-name>
            <param-value>10</param-value>
        </init-param>
        <init-param>
    <param-name>org.atmosphere.cpr.Broadcaster.supportOutOfOrderBroadcast</param-name>
  <param-value>true</param-value>
 </init-param>
 <init-param>
            <param-name>org.atmosphere.useWebSocket</param-name>
            <param-value>false</param-value>
        </init-param>
        <init-param>
            <param-name>org.atmosphere.cpr.asyncSupport</param-name>
            <param-value>org.atmosphere.container.Servlet30CometSupport</param-value>
        </init-param>
        <init-param> 
 <param-name>com.ibm.ws.webcontainer.async-supported</param-name> 
 <param-value>true</param-value> 
 </init-param> 
        <load-on-startup>0</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>AtmosphereServlet</servlet-name>
        <url-pattern>/broadcast/*</url-pattern>
    </servlet-mapping>

After some more investigation when this happens the re-established long poll from the client seems to be hung from that point onwards, any broadcasts during that time fails. Our load balancer seems to kill the connection after a minute and the long-poll reconnects and works fine. If the load balancer is turned off the connection stays up until the default timeout on the atmosphere client kicks in and closes the connection.

During this time if I close the client the following exception is thrown in the atmosphere logs:

2016-08-02 15:02:17,812 [WebContainer : 8] atmosphere.cpr.AsynchronousProcessor ERROR - Failed to cancel resource: 361cc603-5ece-433d-a573-ffef70a12e5c
java.lang.IllegalArgumentException: argument type mismatch
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56)
    at java.lang.reflect.Method.invoke(Method.java:620)
    at org.atmosphere.util.Utils.invoke(Utils.java:209)
    at org.atmosphere.config.managed.ManagedAtmosphereHandler.invoke(ManagedAtmosphereHandler.java:335)
    at org.atmosphere.config.managed.ManagedAtmosphereHandler.onStateChange(ManagedAtmosphereHandler.java:209)
    at org.atmosphere.cpr.AsynchronousProcessor.invokeAtmosphereHandler(AsynchronousProcessor.java:544)
    at org.atmosphere.cpr.AsynchronousProcessor.completeLifecycle(AsynchronousProcessor.java:486)
    at org.atmosphere.interceptor.OnDisconnectInterceptor.inspect(OnDisconnectInterceptor.java:77)
    at org.atmosphere.cpr.AsynchronousProcessor.invokeInterceptors(AsynchronousProcessor.java:340)
    at org.atmosphere.cpr.AsynchronousProcessor.action(AsynchronousProcessor.java:199)
    at org.atmosphere.cpr.AsynchronousProcessor.suspended(AsynchronousProcessor.java:115)
    at org.atmosphere.container.Servlet30CometSupport.service(Servlet30CometSupport.java:68)
    at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:2285)
    at org.atmosphere.cpr.AtmosphereServlet.doPost(AtmosphereServlet.java:191)
    at org.atmosphere.cpr.AtmosphereServlet.doGet(AtmosphereServlet.java:177)

LeeDavidMalcolm avatar Aug 04 '16 14:08 LeeDavidMalcolm