This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 2398282835 Correct a regression in the fix for BZ 66508
2398282835 is described below
commit 2398282835af7b88757cec4973518ffad6bb5fef
Author: Mark Thomas <[email protected]>
AuthorDate: Thu Jan 18 18:43:07 2024 +0000
Correct a regression in the fix for BZ 66508
It could could cause an UpgradeProcessor leak in some circumstances
https://bz.apache.org/bugzilla/show_bug.cgi?id=66508
---
.../server/WsRemoteEndpointImplServer.java | 66 ++++++++++++----------
webapps/docs/changelog.xml | 8 +++
2 files changed, 44 insertions(+), 30 deletions(-)
diff --git
a/java/org/apache/tomcat/websocket/server/WsRemoteEndpointImplServer.java
b/java/org/apache/tomcat/websocket/server/WsRemoteEndpointImplServer.java
index 325e0dd15e..6e86137b42 100644
--- a/java/org/apache/tomcat/websocket/server/WsRemoteEndpointImplServer.java
+++ b/java/org/apache/tomcat/websocket/server/WsRemoteEndpointImplServer.java
@@ -103,41 +103,47 @@ public class WsRemoteEndpointImplServer extends
WsRemoteEndpointImplBase {
protected boolean acquireMessagePartInProgressSemaphore(byte opCode, long
timeoutExpiry)
throws InterruptedException {
- // Only close requires special handling.
- if (opCode != Constants.OPCODE_CLOSE) {
- return super.acquireMessagePartInProgressSemaphore(opCode,
timeoutExpiry);
- }
-
- int socketWrapperLockCount;
+ /*
+ * Special handling is required only when all of the following are
true:
+ * - A close message is being sent
+ * - This thread currently holds the socketWrapper lock (i.e. the
thread is current processing a socket event)
+ *
+ * Special handling is only possible if the socketWrapper lock is a
ReentrantLock (it will be by default)
+ */
if (socketWrapper.getLock() instanceof ReentrantLock) {
- socketWrapperLockCount = ((ReentrantLock)
socketWrapper.getLock()).getHoldCount();
- } else {
- socketWrapperLockCount = 1;
- }
- while (!messagePartInProgress.tryAcquire()) {
- if (timeoutExpiry < System.currentTimeMillis()) {
- return false;
- }
- try {
- // Release control of the processor
- socketWrapper.setCurrentProcessor(connection);
- // Release the per socket lock(s)
- for (int i = 0; i < socketWrapperLockCount; i++) {
- socketWrapper.getLock().unlock();
- }
- // Provide opportunity for another thread to obtain the
socketWrapper lock
- Thread.yield();
- } finally {
- // Re-obtain the per socket lock(s)
- for (int i = 0; i < socketWrapperLockCount; i++) {
- socketWrapper.getLock().lock();
+ ReentrantLock reentrantLock = (ReentrantLock)
socketWrapper.getLock();
+ if (opCode == Constants.OPCODE_CLOSE &&
reentrantLock.isHeldByCurrentThread()) {
+ int socketWrapperLockCount = reentrantLock.getHoldCount();
+
+ while (!messagePartInProgress.tryAcquire()) {
+ if (timeoutExpiry < System.currentTimeMillis()) {
+ return false;
+ }
+ try {
+ // Release control of the processor
+ socketWrapper.setCurrentProcessor(connection);
+ // Release the per socket lock(s)
+ for (int i = 0; i < socketWrapperLockCount; i++) {
+ socketWrapper.getLock().unlock();
+ }
+ // Provide opportunity for another thread to obtain
the socketWrapper lock
+ Thread.yield();
+ } finally {
+ // Re-obtain the per socket lock(s)
+ for (int i = 0; i < socketWrapperLockCount; i++) {
+ socketWrapper.getLock().lock();
+ }
+ // Re-take control of the processor
+ socketWrapper.takeCurrentProcessor();
+ }
}
- // Re-take control of the processor
- socketWrapper.takeCurrentProcessor();
+
+ return true;
}
}
- return true;
+ // Skip special handling
+ return super.acquireMessagePartInProgressSemaphore(opCode,
timeoutExpiry);
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 4f6ead9029..50d81ad9ac 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -120,6 +120,14 @@
</fix>
</changelog>
</subsection>
+ <subsection name="WebSocket">
+ <changelog>
+ <fix>
+ Correct a regression in the fix for <bug>66508</bug> that could cause
an
+ <code>UpgradeProcessor</code> leak in some circumstances. (markt)
+ </fix>
+ </changelog>
+ </subsection>
</section>
<section name="Tomcat 9.0.85 (remm)" rtext="2024-01-09">
<subsection name="Catalina">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]