Skip to content

Commit 6b6beec

Browse files
committed
Skip close lock if acquired by other thread already
Closes gh-32445 (cherry picked from commit d151931)
1 parent 520a113 commit 6b6beec

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

spring-websocket/src/main/java/org/springframework/web/socket/handler/ConcurrentWebSocketSessionDecorator.java

+22-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -248,30 +248,31 @@ private void limitExceeded(String reason) {
248248

249249
@Override
250250
public void close(CloseStatus status) throws IOException {
251-
this.closeLock.lock();
252-
try {
253-
if (this.closeInProgress) {
254-
return;
255-
}
256-
if (!CloseStatus.SESSION_NOT_RELIABLE.equals(status)) {
257-
try {
258-
checkSessionLimits();
259-
}
260-
catch (SessionLimitExceededException ex) {
261-
// Ignore
251+
if (this.closeLock.tryLock()) {
252+
try {
253+
if (this.closeInProgress) {
254+
return;
262255
}
263-
if (this.limitExceeded) {
264-
if (logger.isDebugEnabled()) {
265-
logger.debug("Changing close status " + status + " to SESSION_NOT_RELIABLE.");
256+
if (!CloseStatus.SESSION_NOT_RELIABLE.equals(status)) {
257+
try {
258+
checkSessionLimits();
259+
}
260+
catch (SessionLimitExceededException ex) {
261+
// Ignore
262+
}
263+
if (this.limitExceeded) {
264+
if (logger.isDebugEnabled()) {
265+
logger.debug("Changing close status " + status + " to SESSION_NOT_RELIABLE.");
266+
}
267+
status = CloseStatus.SESSION_NOT_RELIABLE;
266268
}
267-
status = CloseStatus.SESSION_NOT_RELIABLE;
268269
}
270+
this.closeInProgress = true;
271+
super.close(status);
272+
}
273+
finally {
274+
this.closeLock.unlock();
269275
}
270-
this.closeInProgress = true;
271-
super.close(status);
272-
}
273-
finally {
274-
this.closeLock.unlock();
275276
}
276277
}
277278

0 commit comments

Comments
 (0)