Skip to content

Commit

Permalink
Guard the websocket upgrade to only happen once for a request.
Browse files Browse the repository at this point in the history
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 <arjan.tijms@omnifish.ee>
  • Loading branch information
arjantijms committed Jan 23, 2024
1 parent 5d7f6d7 commit 73b0536
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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
*
Expand Down Expand Up @@ -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 =
Expand All @@ -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);
Expand Down

0 comments on commit 73b0536

Please sign in to comment.