{"action":"created","issue":{"url":"https://api.github.com/repos/Atmosphere/atmosphere/issues/1983","labels_url":"https://api.github.com/repos/Atmosphere/atmosphere/issues/1983/labels{/name}","comments_url":"https://api.github.com/repos/Atmosphere/atmosphere/issues/1983/comments","events_url":"https://api.github.com/repos/Atmosphere/atmosphere/issues/1983/events","html_url":"https://github.com/Atmosphere/atmosphere/issues/1983","id":79466158,"number":1983,"title":"Atmosphere 2.3.1: NPE on JSR356Endpoint close event","user":{"login":"timofeevda","id":989338,"avatar_url":"https://avatars.githubusercontent.com/u/989338?v=3","gravatar_id":"","url":"https://api.github.com/users/timofeevda","html_url":"https://github.com/timofeevda","followers_url":"https://api.github.com/users/timofeevda/followers","following_url":"https://api.github.com/users/timofeevda/following{/other_user}","gists_url":"https://api.github.com/users/timofeevda/gists{/gist_id}","starred_url":"https://api.github.com/users/timofeevda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timofeevda/subscriptions","organizations_url":"https://api.github.com/users/timofeevda/orgs","repos_url":"https://api.github.com/users/timofeevda/repos","events_url":"https://api.github.com/users/timofeevda/events{/privacy}","received_events_url":"https://api.github.com/users/timofeevda/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Atmosphere/atmosphere/labels/2.3.2","name":"2.3.2","color":"bfe5bf"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-05-22T14:01:48Z","updated_at":"2015-05-22T16:27:55Z","closed_at":"2015-05-22T15:04:54Z","body":"Environment: Atmosphere 2.3.1 + Tomcat 8.0.22 + JSR356AsyncSupport\r\n\r\nI get following exception when websocket connection is being closed on browser page refresh:\r\n```java\r\n22.05.2015 15:58:17 [http-nio-8080-exec-10] org.atmosphere.container.JSR356Endpoint ERROR -- \r\njava.lang.NullPointerException\r\n\tat org.atmosphere.websocket.DefaultWebSocketProcessor.executeClose(DefaultWebSocketProcessor.java:677)\r\n\tat org.atmosphere.websocket.DefaultWebSocketProcessor.close(DefaultWebSocketProcessor.java:625)\r\n\tat org.atmosphere.container.JSR356Endpoint.onClose(JSR356Endpoint.java:268)\r\n\tat org.apache.tomcat.websocket.WsSession.fireEndpointOnClose(WsSession.java:527)\r\n\tat org.apache.tomcat.websocket.WsSession.onClose(WsSession.java:511)\r\n\tat org.apache.tomcat.websocket.WsFrameBase.processDataControl(WsFrameBase.java:342)\r\n\tat org.apache.tomcat.websocket.WsFrameBase.processData(WsFrameBase.java:284)\r\n\tat org.apache.tomcat.websocket.WsFrameBase.processInputBuffer(WsFrameBase.java:130)\r\n\tat org.apache.tomcat.websocket.server.WsFrameServer.onDataAvailable(WsFrameServer.java:60)\r\n\tat org.apache.tomcat.websocket.server.WsHttpUpgradeHandler$WsReadListener.onDataAvailable(WsHttpUpgradeHandler.java:203)\r\n\tat org.apache.coyote.http11.upgrade.AbstractServletInputStream.onDataAvailable(AbstractServletInputStream.java:198)\r\n\tat org.apache.coyote.http11.upgrade.AbstractProcessor.upgradeDispatch(AbstractProcessor.java:96)\r\n\tat org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:663)\r\n\tat org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1521)\r\n\tat org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1478)\r\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)\r\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)\r\n\tat org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)\r\n\tat java.lang.Thread.run(Thread.java:745)\r\n```\r\n\r\nBased on my investigation \"asynchronousProcessor\" variable in DefaultWebSocketProcessor is null in this case. This happens because \"started\" method is never invoked by atmosphere framework because the creation of JSR356Endpoint in JSR356AsyncSupport occurs later and this startup hook simply goes to the list of hooks and is never invoked.\r\n\r\n```java\r\nconfig.startupHook(new AtmosphereConfig.StartupHook() {\r\n            @Override\r\n            public void started(final AtmosphereFramework framework) {\r\n                if (AsynchronousProcessor.class.isAssignableFrom(framework.getAsyncSupport().getClass())) {\r\n                    asynchronousProcessor = AsynchronousProcessor.class.cast(framework.getAsyncSupport());\r\n                } else {\r\n                    asynchronousProcessor = new AsynchronousProcessor(framework.getAtmosphereConfig()) {\r\n                        @Override\r\n                        public Action service(AtmosphereRequest req, AtmosphereResponse res) throws IOException, ServletException {\r\n                            return framework.getAsyncSupport().service(req, res);\r\n                        }\r\n                    };\r\n                }\r\n            }\r\n        });\r\n```\r\n\r\nApplication  deployment: there is an unpacked folder in Tomcat webapps directory. On start Tomcats loads apps located in this directory, so the process is pretty straightforward.\r\n\r\nPart of the web.xml file:\r\n```xml\r\n <servlet>\r\n        <description>AtmosphereServlet</description>\r\n        <servlet-name>AtmosphereServlet</servlet-name>\r\n        <servlet-class>org.atmosphere.cpr.AtmosphereServlet</servlet-class>\r\n        <init-param>            \r\n            <param-name>org.atmosphere.disableOnStateEvent</param-name>\r\n            <param-value>true</param-value>\r\n        </init-param>       \r\n        <init-param>\r\n            <param-name>org.atmosphere.cpr.broadcaster.shareableThreadPool</param-name>\r\n            <param-value>true</param-value>\r\n        </init-param>\r\n        <init-param>\r\n            <param-name>org.atmosphere.cpr.broadcaster.maxAsyncWriteThreads</param-name>\r\n            <param-value>32</param-value>\r\n        </init-param>\r\n        <load-on-startup>1</load-on-startup>\r\n        <async-supported>true</async-supported>\r\n    </servlet>\r\n```\r\n\r\nIn any case JSR356Endpoint creation leading to creation of new DefaultWebSocketProcessor happens on first websocket connection when Atmosphere framework have been already started.\r\n\r\nI guess this is very similar to this case discussed in mailing list https://groups.google.com/d/msg/atmosphere-framework/365yvg-UflQ/k73IFY3laB8J"},"comment":{"url":"https://api.github.com/repos/Atmosphere/atmosphere/issues/comments/104704646","html_url":"https://github.com/Atmosphere/atmosphere/issues/1983#issuecomment-104704646","issue_url":"https://api.github.com/repos/Atmosphere/atmosphere/issues/1983","id":104704646,"user":{"login":"timofeevda","id":989338,"avatar_url":"https://avatars.githubusercontent.com/u/989338?v=3","gravatar_id":"","url":"https://api.github.com/users/timofeevda","html_url":"https://github.com/timofeevda","followers_url":"https://api.github.com/users/timofeevda/followers","following_url":"https://api.github.com/users/timofeevda/following{/other_user}","gists_url":"https://api.github.com/users/timofeevda/gists{/gist_id}","starred_url":"https://api.github.com/users/timofeevda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timofeevda/subscriptions","organizations_url":"https://api.github.com/users/timofeevda/orgs","repos_url":"https://api.github.com/users/timofeevda/repos","events_url":"https://api.github.com/users/timofeevda/events{/privacy}","received_events_url":"https://api.github.com/users/timofeevda/received_events","type":"User","site_admin":false},"created_at":"2015-05-22T16:27:55Z","updated_at":"2015-05-22T16:27:55Z","body":"I've just made brief tests with 2.3.2-SNAPSHOT and applied 1984. Looks like now everything is OK. Thanks."}}