This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new c89e047b36 Remainder of BZ 69920 fix. General message sending over
closed session.
c89e047b36 is described below
commit c89e047b36ad83d09eb7927b37d42ffc24b545b1
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Jan 14 08:38:29 2026 +0000
Remainder of BZ 69920 fix. General message sending over closed session.
Switch to IOException if a message is sent when the session is closed
This provides consistency with sending using Writer and OutputStream
https://bz.apache.org/bugzilla/show_bug.cgi?id=69920
---
.../tomcat/websocket/WsRemoteEndpointImplBase.java | 18 ++++++++++++++----
webapps/docs/changelog.xml | 6 ++++++
2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
b/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
index a277aa6a0e..cd1414f047 100644
--- a/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
+++ b/java/org/apache/tomcat/websocket/WsRemoteEndpointImplBase.java
@@ -412,7 +412,12 @@ public abstract class WsRemoteEndpointImplBase implements
RemoteEndpoint {
// Actual write has to be outside sync block to avoid possible
// deadlock between messagePartLock and writeLock in
// o.a.coyote.http11.upgrade.AbstractServletOutputStream
- writeMessagePart(mp);
+ try {
+ writeMessagePart(mp);
+ } catch (IOException ioe) {
+ handler.onResult(new SendResult(getSession(), ioe));
+ return;
+ }
}
}
@@ -440,7 +445,12 @@ public abstract class WsRemoteEndpointImplBase implements
RemoteEndpoint {
// Actual write has to be outside sync block to avoid possible
// deadlock between messagePartLock and writeLock in
// o.a.coyote.http11.upgrade.AbstractServletOutputStream
- writeMessagePart(mpNext);
+ try {
+ writeMessagePart(mpNext);
+ } catch (IOException ioe) {
+ handler.onResult(new SendResult(getSession(), ioe));
+ return;
+ }
}
wsSession.updateLastActiveWrite();
@@ -453,9 +463,9 @@ public abstract class WsRemoteEndpointImplBase implements
RemoteEndpoint {
}
- void writeMessagePart(MessagePart mp) {
+ void writeMessagePart(MessagePart mp) throws IOException {
if (closed) {
- throw new
IllegalStateException(sm.getString("wsRemoteEndpoint.closed"));
+ throw new IOException(sm.getString("wsRemoteEndpoint.closed"));
}
if (Constants.INTERNAL_OPCODE_FLUSH == mp.getOpCode()) {
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 25f40205aa..1140933763 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -373,6 +373,12 @@
client's preferred local and the local and remote host name, address
and
port information. (markt)
</add>
+ <fix>
+ <bug>69920</bug>: When attempting to write a message via a WebSocket
+ session that has been closed, throw an <code>IOException</code> rather
+ than an <code>IllegalStateExcpetion</code> for consistency with
+ <code>Writer</code> and <code>OutputStream</code>. (markt)
+ </fix>
<!-- Entries for backport and removal before 12.0.0-M1 below this line
-->
<fix>
<bug>69920</bug>: When attempting to write to a closed
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]