Skip to content

Commit 9119fbb

Browse files
caaladorclaude
andauthored
fix: ensure session lock is held during node state checks in StreamRequestHandler (#22765)
StreamRequestHandler.callElementResourceHandler was performing node state checks (isInert, isEnabled, isAttached, isVisible) without holding the session lock, creating a race condition where node state could change between validation and handler execution. This change moves all node state checks inside a single session lock block to ensure thread-safe access throughout the validation process. The nested lock for UploadHandler has been removed as it's now redundant. Fixes #22746 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent bc5ca60 commit 9119fbb

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

flow-server/src/main/java/com/vaadin/flow/server/communication/StreamRequestHandler.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -139,21 +139,21 @@ private void callElementResourceHandler(VaadinSession session,
139139
Element owner = elementRequest.getOwner();
140140
StateNode node = owner.getNode();
141141

142-
if (blockInert(elementRequest, node)
143-
|| blockDisabled(elementRequest, node) || !node.isAttached()
144-
|| !node.isVisible()) {
145-
response.sendError(HttpStatusCode.FORBIDDEN.getCode(),
146-
"Resource not available");
147-
return;
148-
}
142+
session.lock();
143+
try {
144+
if (blockInert(elementRequest, node)
145+
|| blockDisabled(elementRequest, node) || !node.isAttached()
146+
|| !node.isVisible()) {
147+
response.sendError(HttpStatusCode.FORBIDDEN.getCode(),
148+
"Resource not available");
149+
return;
150+
}
149151

150-
if (elementRequest
151-
.getElementRequestHandler() instanceof UploadHandler) {
152-
// Validate upload security key. Else respond with
153-
// FORBIDDEN.
154-
PathData parts = parsePath(pathInfo);
155-
session.lock();
156-
try {
152+
if (elementRequest
153+
.getElementRequestHandler() instanceof UploadHandler) {
154+
// Validate upload security key. Else respond with
155+
// FORBIDDEN.
156+
PathData parts = parsePath(pathInfo);
157157
String secKey = elementRequest.getId();
158158
if (secKey == null || !MessageDigest.isEqual(
159159
secKey.getBytes(StandardCharsets.UTF_8),
@@ -187,9 +187,9 @@ private void callElementResourceHandler(VaadinSession session,
187187
"Resource not available");
188188
return;
189189
}
190-
} finally {
191-
session.unlock();
192190
}
191+
} finally {
192+
session.unlock();
193193
}
194194
elementRequest.getElementRequestHandler().handleRequest(request,
195195
response, session, elementRequest.getOwner());

0 commit comments

Comments
 (0)