forked from wso2/wso2-synapse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request wso2#2114 from malakaganga/add_separate_worker_poo…
…l_183 Fix Passthrough Threads getting stuck due to request message discard
- Loading branch information
Showing
6 changed files
with
164 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
.../core/nhttp/src/main/java/org/apache/synapse/transport/passthru/MessageDiscardWorker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/** | ||
* Copyright (c) 2023, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.synapse.transport.passthru; | ||
|
||
import org.apache.axis2.AxisFault; | ||
import org.apache.axis2.context.MessageContext; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.apache.http.nio.NHttpClientConnection; | ||
import org.apache.http.nio.NHttpServerConnection; | ||
import org.apache.synapse.transport.passthru.config.TargetConfiguration; | ||
import org.apache.synapse.transport.passthru.util.RelayUtils; | ||
|
||
public class MessageDiscardWorker implements Runnable { | ||
|
||
private Log log = LogFactory.getLog(MessageDiscardWorker.class); | ||
private ClientWorker clientWorker = null; | ||
|
||
TargetConfiguration targetConfiguration = null; | ||
|
||
private TargetResponse response = null; | ||
|
||
private MessageContext requestMessageContext; | ||
|
||
NHttpClientConnection conn = null; | ||
|
||
public MessageDiscardWorker(MessageContext requestMsgContext, TargetResponse response, | ||
TargetConfiguration targetConfiguration, ClientWorker clientWorker, NHttpClientConnection conn) { | ||
this.response = response; | ||
this.requestMessageContext = requestMsgContext; | ||
this.targetConfiguration = targetConfiguration; | ||
this.clientWorker = clientWorker; | ||
this.conn = conn; | ||
} | ||
|
||
public void run() { | ||
|
||
// If an error has happened in the request processing, consumes the data in pipe completely and discard it | ||
try { | ||
RelayUtils.discardRequestMessage(requestMessageContext); | ||
} catch (AxisFault af) { | ||
log.error("Fault discarding request message", af); | ||
} | ||
|
||
targetConfiguration.getWorkerPool().execute(clientWorker); | ||
|
||
targetConfiguration.getMetrics().incrementMessagesReceived(); | ||
|
||
NHttpServerConnection sourceConn = (NHttpServerConnection) requestMessageContext.getProperty( | ||
PassThroughConstants.PASS_THROUGH_SOURCE_CONNECTION); | ||
if (sourceConn != null) { | ||
sourceConn.getContext().setAttribute(PassThroughConstants.RES_HEADER_ARRIVAL_TIME, | ||
conn.getContext() | ||
.getAttribute(PassThroughConstants.RES_HEADER_ARRIVAL_TIME) | ||
); | ||
conn.getContext().removeAttribute(PassThroughConstants.RES_HEADER_ARRIVAL_TIME); | ||
|
||
sourceConn.getContext().setAttribute(PassThroughConstants.REQ_DEPARTURE_TIME, | ||
conn.getContext() | ||
.getAttribute(PassThroughConstants.REQ_DEPARTURE_TIME) | ||
); | ||
conn.getContext().removeAttribute(PassThroughConstants.REQ_DEPARTURE_TIME); | ||
sourceConn.getContext().setAttribute(PassThroughConstants.REQ_TO_BACKEND_WRITE_START_TIME, | ||
conn.getContext() | ||
.getAttribute(PassThroughConstants.REQ_TO_BACKEND_WRITE_START_TIME) | ||
); | ||
|
||
conn.getContext().removeAttribute(PassThroughConstants.REQ_TO_BACKEND_WRITE_START_TIME); | ||
sourceConn.getContext().setAttribute(PassThroughConstants.REQ_TO_BACKEND_WRITE_END_TIME, | ||
conn.getContext() | ||
.getAttribute(PassThroughConstants.REQ_TO_BACKEND_WRITE_END_TIME) | ||
); | ||
conn.getContext().removeAttribute(PassThroughConstants.REQ_TO_BACKEND_WRITE_END_TIME); | ||
sourceConn.getContext().setAttribute(PassThroughConstants.RES_FROM_BACKEND_READ_START_TIME, | ||
conn.getContext() | ||
.getAttribute(PassThroughConstants.RES_FROM_BACKEND_READ_START_TIME) | ||
); | ||
conn.getContext().removeAttribute(PassThroughConstants.RES_FROM_BACKEND_READ_START_TIME); | ||
|
||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters