Bug 61491 - IllegalArgumentException thrown by PerMessageDeflate sendMessagePart()
Summary: IllegalArgumentException thrown by PerMessageDeflate sendMessagePart()
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 8
Classification: Unclassified
Component: WebSocket (show other bugs)
Version: 8.5.20
Hardware: PC All
: P2 critical (vote)
Target Milestone: ----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-09-05 13:29 UTC by email.wtam
Modified: 2017-09-08 09:07 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description email.wtam 2017-09-05 13:29:23 UTC
This issue is similar to https://bz.apache.org/bugzilla/show_bug.cgi?id=59635 but it is happending in another location of the code.   Please refer to the following stack.  

compressedPayload.limit() is zero because of the compressedPayload.flip() call.

Sep 04, 2017 11:10:08 PM org.glassfish.jersey.server.ServerRuntime$Responder writeResponse
SEVERE: Error while closing the output stream in order to commit response.
java.lang.IllegalArgumentException
	at java.nio.Buffer.limit(Unknown Source)
	at org.apache.tomcat.websocket.PerMessageDeflate.sendMessagePart(PerMessageDeflate.java:374)
	at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.startMessage(WsRemoteEndpointImplBase.java:341)
	at org.apache.tomcat.websocket.WsRemoteEndpointImplBase$TextMessageSendHandler.write(WsRemoteEndpointImplBase.java:803)
	at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendStringByCompletion(WsRemoteEndpointImplBase.java:212)
	at org.apache.tomcat.websocket.WsRemoteEndpointAsync.sendText(WsRemoteEndpointAsync.java:47)
	at org.atmosphere.container.version.JSR356WebSocket.write(JSR356WebSocket.java:73)
	at org.atmosphere.websocket.WebSocket.write(WebSocket.java:255)
	at org.atmosphere.websocket.WebSocket.write(WebSocket.java:46)
	at org.atmosphere.cpr.AtmosphereResponseImpl$Stream.write(AtmosphereResponseImpl.java:980)
	at org.glassfish.jersey.servlet.internal.ResponseWriter$NonCloseableOutputStreamWrapper.write(ResponseWriter.java:325)
	at java.io.ByteArrayOutputStream.writeTo(Unknown Source)
	at org.glassfish.jersey.message.internal.CommittingOutputStream.flushBuffer(CommittingOutputStream.java:307)
	at org.glassfish.jersey.message.internal.CommittingOutputStream.commit(CommittingOutputStream.java:261)
	at org.glassfish.jersey.message.internal.CommittingOutputStream.close(CommittingOutputStream.java:276)
	at org.glassfish.jersey.message.internal.OutboundMessageContext.close(OutboundMessageContext.java:877)
	at org.glassfish.jersey.server.ContainerResponse.close(ContainerResponse.java:412)
	at org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:784)
	at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:444)
	at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:434)
	at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:329)
	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
	at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:321)
	at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305)
	at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154)
	at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:473)
	at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427)
	at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:388)
	at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:341)
	at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:228)
	at com.apriori.async.ws.config.AsyncServletContainer.service(AsyncServletContainer.java:108)
	at org.atmosphere.util.AtmosphereFilterChain.doFilter(AtmosphereFilterChain.java:135)
	at org.atmosphere.util.AtmosphereFilterChain.invokeFilterChain(AtmosphereFilterChain.java:96)
	at org.atmosphere.handler.ReflectorServletProcessor$FilterChainServletWrapper.service(ReflectorServletProcessor.java:337)
	at org.atmosphere.handler.ReflectorServletProcessor.onRequest(ReflectorServletProcessor.java:175)
	at org.atmosphere.cpr.AsynchronousProcessor.action(AsynchronousProcessor.java:223)
	at org.atmosphere.cpr.AsynchronousProcessor.suspended(AsynchronousProcessor.java:115)
	at org.atmosphere.container.Servlet30CometSupport.service(Servlet30CometSupport.java:67)
	at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:2287)
	at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(DefaultWebSocketProcessor.java:593)
	at org.atmosphere.websocket.DefaultWebSocketProcessor.open(DefaultWebSocketProcessor.java:224)
	at org.atmosphere.container.JSR356Endpoint.onOpen(JSR356Endpoint.java:264)
	at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler.init(WsHttpUpgradeHandler.java:133)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:914)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1457)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)
Comment 1 Mark Thomas 2017-09-06 19:16:43 UTC
From the stack trace, this appears to be a duplicate of bug 59635.

Are you sure compressedPayload.limit() is zero? 1, 2 and 3 are also possibilities.

What is really needed here is a test case. Can you provide the String that was being sent at the time?

I'll take another look at the code but a reliable test case would make this a lot simpler.
Comment 2 Mark Thomas 2017-09-07 19:21:34 UTC
I've managed to reproduce this.

It is triggered by a zero length message after a non-zero length message when the compression context is retained between messages.

I'm starting to think about a fix.
Comment 3 Mark Thomas 2017-09-08 09:07:07 UTC
Fixed in:
- trunk for 9.0.0.M27 onwards
- 8.5.x for 8.5.21 onwards
- 8.0.x for 8.0.47 onwards
- 7.0.x for 7.0.82 onwards