Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 363381

Summary: NoSessionManager when using suspended Request after WebSocket handshake
Product: [RT] Jetty Reporter: Jan Bartel <janb>
Component: websocketAssignee: Jan Bartel <janb>
Status: RESOLVED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: jetty-inbox, jfarcand
Version: 8.0.2   
Target Milestone: 7.5.x   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Jan Bartel CLA 2011-11-09 15:48:00 EST
From Jeanfrancois Arcand:

Before 8.0.1, I was able to continue using the HttpServletRequest after the WebSocket handshake. That allowed me to run Jersey on top of Jetty WebSocket. Starting in 8.0.2, the HttpServletRequest and its associated Request gets recycled, producing NPE

Here's the link to the Atmosphere issue:
https://github.com/Atmosphere/atmosphere/issues/45
Comment 1 jfarcand CLA 2011-11-09 15:50:15 EST
The test case is here:

https://github.com/Atmosphere/Incubator/blob/master/atmosphere-jquery-pubsub-RequestRecycled.war

Rename to atmosphere-jquery-pubsub.war

Deploy in 8.0.2 and up (8.0.1 works fine)

(1) Enter a topic
(2) connect

All kind of NPEs will be displayed, caused because the Request was recycled

Caused by: 
java.lang.NullPointerException
	at org.eclipse.jetty.server.Request.getServerName(Request.java:1008)
	at org.eclipse.jetty.server.Request.getServerPort(Request.java:1071)
	at org.eclipse.jetty.server.Request.getRequestURL(Request.java:934)
	at javax.servlet.http.HttpServletRequestWrapper.getRequestURL(HttpServletRequestWrapper.java:241)
	at javax.servlet.http.HttpServletRequestWrapper.getRequestURL(HttpServletRequestWrapper.java:241)
	at org.atmosphere.cpr.AtmosphereRequest.getRequestURL(AtmosphereRequest.java:105)
	at javax.servlet.http.HttpServletRequestWrapper.getRequestURL(HttpServletRequestWrapper.java:241)
	at org.atmosphere.cpr.AtmosphereRequest.getRequestURL(AtmosphereRequest.java:105)
	at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:638)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
	at org.atmosphere.util.AtmosphereFilterChain.doFilter(AtmosphereFilterChain.java:155)
	at org.atmosphere.util.AtmosphereFilterChain.invokeFilterChain(AtmosphereFilterChain.java:116)
	at org.atmosphere.handler.ReflectorServletProcessor$FilterChainServletWrapper.service(ReflectorServletProcessor.java:293)
	at org.atmosphere.handler.ReflectorServletProcessor.onRequest(ReflectorServletProcessor.java:151)
	at org.atmosphere.cpr.AsynchronousProcessor.action(AsynchronousProcessor.java:214)
	at org.atmosphere.cpr.AsynchronousProcessor.suspended(AsynchronousProcessor.java:149)
	at org.atmosphere.container.Jetty7CometSupport.service(Jetty7CometSupport.java:82)
	at org.atmosphere.container.JettyCometSupportWithWebSocket.service(JettyCometSupportWithWebSocket.java:85)
	at org.atmosphere.cpr.AtmosphereServlet.doCometSupport(AtmosphereServlet.java:1179)
	at org.atmosphere.websocket.WebSocketProcessor.dispatch(WebSocketProcessor.java:144)
Comment 2 Jan Bartel CLA 2011-11-11 00:00:10 EST
Hi Jeanfrancois,

I've taken a look at your code, the jetty code, and consulted with Greg. I think the atmosphere code is suspending on the request that initiates websocket. The next input that comes in over the websocket connection is then used to wake up the suspended request. 

However, after websocket is established, and the 101 response has gone back, we throw away (ie recycle) the Request and Response as they have no further relevance, as the connection is now speaking websocket.

Greg recommends that you do not suspend on the request that establishes websocket, as the request/response cycle is supposed to be finished when websocket is established.

I will add NPE protection in the Request in any case.

regards
Jan
Comment 3 Jan Bartel CLA 2011-11-14 23:05:28 EST
The Request.getServerName method throws IllegalStateException if the uri is null.
Checked into jetty-7 and will be incorporated into jetty-8 next release.