From 73b05366ce34a07f3b340e076529a128e39aaa9a Mon Sep 17 00:00:00 2001 From: Arjan Tijms Date: Tue, 23 Jan 2024 15:13:41 +0100 Subject: [PATCH] Guard the websocket upgrade to only happen once for a request. Without that guard in place it could happen multiple times as "basic.invoke(req, resp);" could lead to the invocation of another PipeLine executing the same code. Signed-off-by: Arjan Tijms --- .../main/java/org/apache/catalina/core/StandardPipeline.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/appserver/web/web-core/src/main/java/org/apache/catalina/core/StandardPipeline.java b/appserver/web/web-core/src/main/java/org/apache/catalina/core/StandardPipeline.java index d4c2163f6bb..8b8408d242b 100644 --- a/appserver/web/web-core/src/main/java/org/apache/catalina/core/StandardPipeline.java +++ b/appserver/web/web-core/src/main/java/org/apache/catalina/core/StandardPipeline.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2024 Contributors to the Eclipse Foundation. * Copyright (c) 1997-2018 Oracle and/or its affiliates. All rights reserved. * Copyright 2004 The Apache Software Foundation * @@ -586,7 +587,8 @@ private void doInvoke(Request request, Response response, boolean chaining) thro // Calls the protocol handler's init method if the request is marked to be upgraded if (request instanceof org.apache.catalina.connector.Request) { org.apache.catalina.connector.Request connectorRequest = (org.apache.catalina.connector.Request) request; - if (connectorRequest.isUpgrade()) { + + if (connectorRequest.getNote(AFTER_UPGRADE_HANDLER_INITIALIZED) == null && connectorRequest.isUpgrade()) { HttpUpgradeHandler handler = connectorRequest.getHttpUpgradeHandler(); if (handler != null) { WebConnectionImpl webConnectionImpl = @@ -606,6 +608,7 @@ private void doInvoke(Request request, Response response, boolean chaining) thro handler.init(webConnectionImpl); } finally { context.fireContainerEvent(AFTER_UPGRADE_HANDLER_INITIALIZED, handler); + connectorRequest.setNote(AFTER_UPGRADE_HANDLER_INITIALIZED, true); } } else { log.log(SEVERE, PROTOCOL_HANDLER_REQUIRED_EXCEPTION);