Skip to content

Commit

Permalink
Merge pull request #2134 from SavinduDimal/tls-graceful-termination-c…
Browse files Browse the repository at this point in the history
…onfig

Add a configuration parameter to enable/disable graceful TLS connection termination
  • Loading branch information
SavinduDimal authored Feb 9, 2024
2 parents 6666e7e + ce41c7c commit 556303e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -760,8 +760,13 @@ public void timeout(NHttpServerConnection conn) {
}

SourceContext.updateState(conn, ProtocolState.CLOSED);

sourceConfiguration.getSourceConnections().closeConnection(conn, true);

if (conf.isTLSGracefulConnectionTerminationEnabled()) {
sourceConfiguration.getSourceConnections().closeConnection(conn, true);
} else {
sourceConfiguration.getSourceConnections().shutDownConnection(conn, true);
}

if (isTimeoutOccurred) {
rollbackTransaction(conn);
}
Expand Down Expand Up @@ -846,7 +851,13 @@ public void closed(NHttpServerConnection conn) {
metrics.disconnected();

SourceContext.updateState(conn, ProtocolState.CLOSED);
sourceConfiguration.getSourceConnections().closeConnection(conn, isFault);

if (conf.isTLSGracefulConnectionTerminationEnabled()) {
sourceConfiguration.getSourceConnections().closeConnection(conn, isFault);
} else {
sourceConfiguration.getSourceConnections().shutDownConnection(conn, isFault);
}

if (isFault) {
rollbackTransaction(conn);
metrics.exceptionOccured();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,12 @@ public void closed(NHttpClientConnection conn) {
metrics.disconnected();

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

if (conf.isTLSGracefulConnectionTerminationEnabled()) {
targetConfiguration.getConnections().closeConnection(conn, isFault);
} else {
targetConfiguration.getConnections().shutdownConnection(conn, isFault);
}

}

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

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

if (conf.isTLSGracefulConnectionTerminationEnabled()) {
targetConfiguration.getConnections().closeConnection(conn, true);
} else {
targetConfiguration.getConnections().shutdownConnection(conn, true);
}
}

private String workerPoolExhaustedErrorMessage(Object clientWorker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,10 @@ public interface PassThroughConfigPNames {
* Defines whether to ignore case-sensitive headers from excess headers map
*/
public String IGNORE_CASE_SENSITIVE_HEADERS = "ignore_case_sensitive_headers";

/**
* Defines whether TransportHandler and SourceHandler has to enable/disable TLS graceful connection termination
*/
public String TLS_GRACEFUL_CONNECTION_TERMINATION = "tls_graceful_connection_termination";

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public class PassThroughConfiguration {
/** Reverse proxy mode is enabled or not */
private Boolean reverseProxyMode = null;

/** Enables graceful termination for TLS connection */
private Boolean isTLSGracefulConnectionTerminationEnabled = null;

/** Default Synapse service name */
private String passThroughDefaultServiceName = null;

Expand Down Expand Up @@ -151,6 +154,14 @@ public boolean isCloseSocketOnEndpointTimeout() {
, CLOSE_SOCKET_ON_ENDPOINT_TIMEOUT, props);
}

public boolean isTLSGracefulConnectionTerminationEnabled() {
if (isTLSGracefulConnectionTerminationEnabled == null) {
isTLSGracefulConnectionTerminationEnabled = getBooleanProperty(
PassThroughConfigPNames.TLS_GRACEFUL_CONNECTION_TERMINATION, true);
}
return isTLSGracefulConnectionTerminationEnabled;
}

public boolean isConsumeAndDiscard() {
isConsumeAndDiscard =
ConfigurationBuilderUtil.getBooleanProperty(PassThroughConfigPNames.CONSUME_AND_DISCARD,
Expand Down

0 comments on commit 556303e

Please sign in to comment.