https://issues.apache.org/bugzilla/show_bug.cgi?id=54716

Nick Williams <nicho...@nicholaswilliams.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |---

--- Comment #2 from Nick Williams <nicho...@nicholaswilliams.net> ---
This definitely improves robustness, but it does not solve the problem where a
NullPointerException is thrown in BackgroundProcessManeger#unregister(...) if a
Session#close(...) is called in an onOpen method:

Caused by: java.lang.NullPointerException
    at
org.apache.tomcat.websocket.BackgroundProcessManager.unregister(BackgroundProcessManager.java:75)
    at
org.apache.tomcat.websocket.WsWebSocketContainer.unregisterSession(WsWebSocketContainer.java:283)
    at
org.apache.tomcat.websocket.server.WsServerContainer.unregisterSession(WsServerContainer.java:283)
    at
org.apache.tomcat.websocket.WsSession.sendCloseMessage(WsSession.java:357)
    at org.apache.tomcat.websocket.WsSession.close(WsSession.java:305)
    at com.wrox.chat.ChatEndpoint.onOpen(ChatEndpoint.java:54)
    ... 17 more

Calling Session#close(...) from onOpen is a valid use-case: At onOpen I may
check to make sure the user is authenticated, and if not, I need to close the
session.

The root-cause of this NullPointerException is that, in WsWebSocketContainer
and WsProtocolHandler, WsWebSocketContainer#registerSession(...) is called
AFTER onOpen. registerSession ultimately calls
BackgroundProcessManager#register(...), which instantiates the background
thread if it does not already exist. So, if there are NO active Sessions, and a
new Session is created, and that Session is closed onOpen, the background
thread will not already exist when BackgroundProcessManeger#unregister(...) is
called, and that causes the NullPointerException.

There are two possible solutions to this that I can see, though there very well
may be others:

1) In BackgroundProcessManeger#unregister(...), make sure the background thread
is not null before calling #halt().
2) In WsWebSocketContainer and WsProtocolHandler, call registerSession BEFORE
onOpen. This doesn't seem correct to me, but I don't understand it fully.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to