HTTPCLIENT-2107: Threadsafe PoolingHttpClientConnectionManager field volatile access

This commit is contained in:
Carter Kozak 2020-08-10 11:34:24 -04:00 committed by Oleg Kalnichevski
parent f6da2bac6f
commit 4f47c4abc0
1 changed files with 5 additions and 3 deletions

View File

@ -286,10 +286,11 @@ public class PoolingHttpClientConnectionManager
LOG.debug("{}: endpoint leased {}", id, ConnPoolSupport.formatStats(route, state, pool)); LOG.debug("{}: endpoint leased {}", id, ConnPoolSupport.formatStats(route, state, pool));
} }
try { try {
if (TimeValue.isNonNegative(validateAfterInactivity)) { final TimeValue validateAfterInactivitySnapshot = validateAfterInactivity;
if (TimeValue.isNonNegative(validateAfterInactivitySnapshot)) {
final ManagedHttpClientConnection conn = poolEntry.getConnection(); final ManagedHttpClientConnection conn = poolEntry.getConnection();
if (conn != null if (conn != null
&& poolEntry.getUpdated() + validateAfterInactivity.toMilliseconds() <= System.currentTimeMillis()) { && poolEntry.getUpdated() + validateAfterInactivitySnapshot.toMilliseconds() <= System.currentTimeMillis()) {
boolean stale; boolean stale;
try { try {
stale = conn.isStale(); stale = conn.isStale();
@ -407,12 +408,13 @@ public class PoolingHttpClientConnectionManager
LOG.debug("{}: connecting endpoint to {} ({})", ConnPoolSupport.getId(endpoint), host, connectTimeout); LOG.debug("{}: connecting endpoint to {} ({})", ConnPoolSupport.getId(endpoint), host, connectTimeout);
} }
final ManagedHttpClientConnection conn = poolEntry.getConnection(); final ManagedHttpClientConnection conn = poolEntry.getConnection();
final SocketConfig defaultSocketConfigSnapshot = defaultSocketConfig;
this.connectionOperator.connect( this.connectionOperator.connect(
conn, conn,
host, host,
route.getLocalSocketAddress(), route.getLocalSocketAddress(),
connectTimeout, connectTimeout,
defaultSocketConfig != null ? this.defaultSocketConfig : SocketConfig.DEFAULT, defaultSocketConfigSnapshot != null ? defaultSocketConfigSnapshot : SocketConfig.DEFAULT,
context); context);
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("{}: connected {}", ConnPoolSupport.getId(endpoint), ConnPoolSupport.getId(conn)); LOG.debug("{}: connected {}", ConnPoolSupport.getId(endpoint), ConnPoolSupport.getId(conn));