Skip to content

Commit

Permalink
Merge pull request wso2#2093 from malakaganga/fix_close_con
Browse files Browse the repository at this point in the history
Mark connection as failed when TLS tunnel has not been established
  • Loading branch information
malakaganga authored May 15, 2023
2 parents 10e2eb5 + 9c8b8bd commit 2b4f3d3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ public void responseReceived(NHttpClientConnection conn) {
HttpResponse response = conn.getHttpResponse();
ProtocolState connState;
try {
boolean isError = false;
String method = null;
ProxyTunnelHandler tunnelHandler = (ProxyTunnelHandler) context.getAttribute(PassThroughConstants.TUNNEL_HANDLER);
if (tunnelHandler != null && !tunnelHandler.isCompleted()) {
Expand All @@ -333,6 +334,9 @@ public void responseReceived(NHttpClientConnection conn) {
conn.requestOutput();
return;
} else {
// TLS tunnel has not been established, so mark connection as failed to prevent that it is
// returned back into pool
isError = true;
log.warn("Tunnel response failed");
// the reason for getting the targetRequest and calling the consumeError() on pipe. Instead of
// calling the informWriterError(NHTTPClientConnection) is, at this point the
Expand Down Expand Up @@ -367,7 +371,6 @@ public void responseReceived(NHttpClientConnection conn) {
.info((System.currentTimeMillis() - startTime) + "|HTTP|"
+ TargetContext.getRequest(conn).getUrl().toString() + "|BACKEND LATENCY");
}
boolean isError = false;
if (connState != ProtocolState.REQUEST_DONE) {
isError = true;
MessageContext requestMsgContext = TargetContext.get(conn).getRequestMsgCtx();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void start(NHttpClientConnection conn) {
try {
// this is a connection we should not re-use
TargetContext.updateState(conn, ProtocolState.CLOSING);
targetConfiguration.getConnections().shutdownConnection(conn);
targetConfiguration.getConnections().shutdownConnection(conn, forceShutdownConnectionOnComplete);

} catch (Exception ignore) {

Expand Down Expand Up @@ -183,7 +183,7 @@ public int read(NHttpClientConnection conn, ContentDecoder decoder) throws IOExc
if (!this.connStrategy.keepAlive(response, conn.getContext()) || forceShutdownConnectionOnComplete) {
TargetContext.updateState(conn, ProtocolState.CLOSED);

targetConfiguration.getConnections().shutdownConnection(conn);
targetConfiguration.getConnections().shutdownConnection(conn, forceShutdownConnectionOnComplete);
} else {
if (conn instanceof LoggingNHttpClientConnection) {
((LoggingNHttpClientConnection) conn).setReleaseConn(true);
Expand Down

0 comments on commit 2b4f3d3

Please sign in to comment.