You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2021/12/23 08:51:03 UTC
[Bug 65763] New: WsRemoteEndpointImplBase#sendMessageBlock cannot close session properly when have TimeoutException
https://bz.apache.org/bugzilla/show_bug.cgi?id=65763
Bug ID: 65763
Summary: WsRemoteEndpointImplBase#sendMessageBlock cannot close
session properly when have TimeoutException
Product: Tomcat 9
Version: 9.0.44
Hardware: PC
OS: Mac OS X 10.1
Status: NEW
Severity: normal
Priority: P2
Component: WebSocket
Assignee: dev@tomcat.apache.org
Reporter: qintai.ltc@oceanbase.com
Target Milestone: -----
Firstly, I found this exception:
####
java.io.IOException: java.util.concurrent.TimeoutException
at
org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendMessageBlock(WsRemoteEndpointImplBase.java:324)
at
org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendMessageBlock(WsRemoteEndpointImplBase.java:259)
at
####
It happens in
org.apache.tomcat.websocket.WsRemoteEndpointImplBase#sendMessageBlock(byte,
java.nio.ByteBuffer, boolean, long):
###java
if (!bsh.getSendResult().isOK()) {
messagePartInProgress.release();
Throwable t = bsh.getSendResult().getException();
wsSession.doClose(new CloseReason(CloseCodes.GOING_AWAY,
t.getMessage()),
new CloseReason(CloseCodes.CLOSED_ABNORMALLY,
t.getMessage()), true);
throw new IOException (t);
}
###
Actually, it is caused by
org.apache.tomcat.websocket.WsRemoteEndpointImplClient#doWrite which has a
LongToIntegerFuture.get timeout exception:
###java
try {
channel.write(byteBuffer).get(timeout, TimeUnit.MILLISECONDS);
} catch (InterruptedException | ExecutionException |
TimeoutException e) {
handler.onResult(new SendResult(e));
return;
}
###
But "writing" value is not set to "false" which has been set "true" in
org.apache.tomcat.websocket.AsyncChannelWrapperSecure#write(java.nio.ByteBuffer).
Only in org.apache.tomcat.websocket.AsyncChannelWrapperSecure.WriteTask,
"writing" will be reset to "false", but WriteTask may not finish when
LongToIntegerFuture.get timeout happens. This problem may like
https://bz.apache.org/bugzilla/show_bug.cgi?id=61003, but writing.set(false)
doesn't work in this timeout situation.
When WsRemoteEndpointImplBase#sendMessageBlock get TimeoutException, it will
try to close session, see "wsSession.doClose(new
CloseReason(CloseCodes.GOING_AWAY, t.getMessage())".
This method "wsSession.doClose" will set state = State.OUTPUT_CLOSED and send a
close message (org.apache.tomcat.websocket.WsSession#sendCloseMessage). But it
will case exception, because "writing" value is still "true":
###
Caused by: java.lang.IllegalStateException: Concurrent write operations are
not permitted
at
org.apache.tomcat.websocket.AsyncChannelWrapperSecure.write(AsyncChannelWrapperSecure.java:117)
at
org.apache.tomcat.websocket.WsRemoteEndpointImplClient.doWrite(WsRemoteEndpointImplClient.java:62)
at
org.apache.tomcat.websocket.WsRemoteEndpointImplBase$OutputBufferSendHandler.write(WsRemoteEndpointImplBase.java:893)
at
org.apache.tomcat.websocket.WsRemoteEndpointImplBase.writeMessagePart(WsRemoteEndpointImplBase.java:506)
at
org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendMessageBlock(WsRemoteEndpointImplBase.java:311)
at
org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendMessageBlock(WsRemoteEndpointImplBase.java:259)
at
org.apache.tomcat.websocket.WsSession.sendCloseMessage(WsSession.java:613)
at org.apache.tomcat.websocket.WsSession.doClose(WsSession.java:498)
at
org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendMessageBlock(WsRemoteEndpointImplBase.java:322)
###
In org.apache.tomcat.websocket.WsSession#sendCloseMessage, it doesn't catch
IllegalStateException and close websocket channel:
###java
try {
wsRemoteEndpoint.sendMessageBlock(Constants.OPCODE_CLOSE, msg,
true);
} catch (IOException | WritePendingException e) {
// Failed to send close message. Close the socket and let the
caller
// deal with the Exception
if (log.isDebugEnabled()) {
log.debug(sm.getString("wsSession.sendCloseFail", id), e);
}
wsRemoteEndpoint.close();
###
And this session may cannot be closed again because state has been set to
"OUTPUT_CLOSED".
I think IllegalStateException should be caught in
org.apache.tomcat.websocket.WsSession#sendCloseMessage or a better way to close
session when timeout happens.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
[Bug 65763] WsRemoteEndpointImplBase#sendMessageBlock cannot close session properly when have TimeoutException
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65763
Mark Thomas <ma...@apache.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |FIXED
--- Comment #3 from Mark Thomas <ma...@apache.org> ---
Thanks for the report and the analysis.
After reviewing the code, I think catching IllegalStateException is the way to
handle this.
Fixed in:
- 10.1.x for 10.1.0-M9 onwards
- 10.0.x for 10.0.15 onwards
- 9.0.x for 9.0.57 onwards
- 8.5.x for 8.5.74 onwards
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
[Bug 65763] WsRemoteEndpointImplBase#sendMessageBlock cannot close session properly when have TimeoutException
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65763
--- Comment #1 from alex <qi...@oceanbase.com> ---
Created attachment 38141
--> https://bz.apache.org/bugzilla/attachment.cgi?id=38141&action=edit
Caused by: java.lang.IllegalStateException: Concurrent write
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
[Bug 65763] WsRemoteEndpointImplBase#sendMessageBlock cannot close session properly when have TimeoutException
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65763
--- Comment #4 from alex <qi...@oceanbase.com> ---
(In reply to Mark Thomas from comment #3)
> Thanks for the report and the analysis.
>
> After reviewing the code, I think catching IllegalStateException is the way
> to handle this.
>
> Fixed in:
> - 10.1.x for 10.1.0-M9 onwards
> - 10.0.x for 10.0.15 onwards
> - 9.0.x for 9.0.57 onwards
> - 8.5.x for 8.5.74 onwards
Yes, I agree with you.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
[Bug 65763] WsRemoteEndpointImplBase#sendMessageBlock cannot close session properly when have TimeoutException
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65763
--- Comment #2 from alex <qi...@oceanbase.com> ---
Comment on attachment 38141
--> https://bz.apache.org/bugzilla/attachment.cgi?id=38141
Caused by: java.lang.IllegalStateException: Concurrent write
>
> Caused by: java.lang.IllegalStateException: Concurrent write operations are not permitted
> at org.apache.tomcat.websocket.AsyncChannelWrapperSecure.write(AsyncChannelWrapperSecure.java:117)
> at org.apache.tomcat.websocket.WsRemoteEndpointImplClient.doWrite(WsRemoteEndpointImplClient.java:62)
> at org.apache.tomcat.websocket.WsRemoteEndpointImplBase$OutputBufferSendHandler.write(WsRemoteEndpointImplBase.java:893)
> at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.writeMessagePart(WsRemoteEndpointImplBase.java:506)
> at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendMessageBlock(WsRemoteEndpointImplBase.java:311)
> at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendMessageBlock(WsRemoteEndpointImplBase.java:259)
> at org.apache.tomcat.websocket.WsSession.sendCloseMessage(WsSession.java:613)
> at org.apache.tomcat.websocket.WsSession.doClose(WsSession.java:498)
> at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendMessageBlock(WsRemoteEndpointImplBase.java:322)
> at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendMessageBlock(WsRemoteEndpointImplBase.java:251)
> at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendPartialString(WsRemoteEndpointImplBase.java:224)
> at org.apache.tomcat.websocket.WsRemoteEndpointBasic.sendText(WsRemoteEndpointBasic.java:49)
> at org.springframework.web.socket.adapter.standard.StandardWebSocketSession.sendTextMessage(StandardWebSocketSession.java:215)
> at org.springframework.web.socket.adapter.AbstractWebSocketSession.sendMessage(AbstractWebSocketSession.java:106)
> at org.springframework.web.socket.sockjs.client.WebSocketClientSockJsSession.sendInternal(WebSocketClientSockJsSession.java:121)
> at org.springframework.web.socket.sockjs.client.AbstractClientSockJsSession.sendMessage(AbstractClientSockJsSession.java:162)
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org