Search code examples
tomcatgrailswebsocketatmosphere

Atmosphere on grails hang after a few minutes


I'm using the grails-events-push plugin and all goes well, but when the system is idle for a while (about 3 minutes), the connection is lost and it cannot reconnect with the server. When I refresh the page everything goes well again.

This is the error on chrome: WebSocket connection to 'ws://192.168.1.109:8080/EasyRestaurant//g-eventsbus/eventsbus?X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=2.1.5-jquery&X-Atmosphere-Transport=websocket&X-Atmosphere-TrackMessageSize=true&X-Cache-Date=0&Content-Type=application/json&X-atmo-protocol=true' failed: Received a broken close frame containing a reserved status code.

After this error if I try to send an event another one appears: No suspended connection available. Make sure atmosphere.subscribe has been called and request.onOpen invoked before invoking this method.

I'm using atmosphere-javascript-2.1.5 in tomcat:7.0.52.1 (events-push:1.0.0.BUILD-SNAPSHOT and org.grails.plugins:events:1.0.0.BUILD-SNAPSHOT) I don't know which version of atmosphere use the grails-events-plugin.

Anyone knows where the problem is? Is it the atmosphere client in javascript or the grails-events-push plugin in grails? Is it tomcat?

Thanks!


Solution

  • I use the two interceptors below in my atmosphere plugin and sample app and haven't had any problems with disconnects or timeouts.

    org.atmosphere.interceptor.AtmosphereResourceLifecycleInterceptor
    org.atmosphere.interceptor.HeartbeatInterceptor
    

    I took a quick look through Stephane's plugin code, but I didn't see an easy way to configure these.

    You should be able to try the latest atmosphere release by adding the compile line below to your app's BuildConfig.groovy dependencies section. I'd give that a try first.

    dependencies {
        // other dependencies
        compile 'org.atmosphere:atmosphere-runtime:2.1.3'
    }
    

    You could use my plugin, but you'd have to add your own events handling code. In my private app I use a Grails service to handle sending events and notifications, and it's not that difficult to implement.