Skip to content

Commit

Permalink
Merge pull request wso2#2086 from malakaganga/fix_passthrough_rem_dis…
Browse files Browse the repository at this point in the history
…card_master

Fix not closing TLS session prior to tcp connection close in TargetHandler side
  • Loading branch information
malakaganga authored May 11, 2023
2 parents 0656fd0 + fcdd441 commit f87b1aa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ public void closed(NHttpClientConnection conn) {
metrics.disconnected();

TargetContext.updateState(conn, ProtocolState.CLOSED);
targetConfiguration.getConnections().shutdownConnection(conn, isFault);
targetConfiguration.getConnections().closeConnection(conn, isFault);

}

Expand Down Expand Up @@ -871,7 +871,7 @@ public void timeout(NHttpClientConnection conn) {
}

TargetContext.updateState(conn, ProtocolState.CLOSED);
targetConfiguration.getConnections().shutdownConnection(conn, true);
targetConfiguration.getConnections().closeConnection(conn, true);
}

private boolean isResponseHaveBodyExpected(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,33 @@ public void shutdownConnection(NHttpClientConnection conn, boolean isError) {
}
}

/**
* Close a connection gracefully.
*
* @param conn the connection that needs to be closed.
* @param isError whether an error is causing the close of the connection.
* When an error is causing a close of a connection we should
* not release the associated buffers into the pool.
*/
public void closeConnection(NHttpClientConnection conn, boolean isError) {
HostConnections pool = (HostConnections) conn.getContext().getAttribute(
PassThroughConstants.CONNECTION_POOL);

TargetContext.get(conn).reset(isError);

if (pool != null) {
pool.forget(conn);
} else {
// we shouldn't get here
log.fatal("Connection without a pool. Something wrong. Need to fix.");
}

try {
conn.close();
} catch (IOException ignored) {
}
}

/**
* Release an active connection to the pool
*
Expand Down

0 comments on commit f87b1aa

Please sign in to comment.