Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Fix race condition causing 'pool not open' errors (#5882)
Browse files Browse the repository at this point in the history
Fixed a race condition where we would potentially attempt to use a Cassandra client pool that we had already closed.
  • Loading branch information
gsheasby authored Jan 27, 2022
1 parent a8ebaa6 commit 4ebeb74
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.palantir.logsafe.exceptions.SafeIllegalStateException;
import com.palantir.logsafe.logger.SafeLogger;
import com.palantir.logsafe.logger.SafeLoggerFactory;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -50,6 +51,7 @@
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import org.apache.cassandra.thrift.NotFoundException;
import org.apache.cassandra.thrift.TokenRange;

Expand Down Expand Up @@ -318,10 +320,16 @@ private void setServersInPoolTo(Set<InetSocketAddress> desiredServers) {
serversToRemove.forEach(cassandra::removePool);

if (!(serversToAdd.isEmpty() && serversToRemove.isEmpty())) { // if we made any changes
// Log IP addresses along with hostnames
Set<InetAddress> addressesToAdd =
serversToAdd.stream().map(InetSocketAddress::getAddress).collect(Collectors.toSet());
Set<InetAddress> addressesToRemove =
serversToRemove.stream().map(InetSocketAddress::getAddress).collect(Collectors.toSet());

log.info(
"Servers to add and remove, inside the if block",
SafeArg.of("serversToAdd", serversToAdd),
SafeArg.of("serversToRemove", serversToRemove));
"Added and removed servers from the client pool",
SafeArg.of("serversAdded", addressesToAdd),
SafeArg.of("serversRemoved", addressesToRemove));
sanityCheckRingConsistency();
cassandra.refreshTokenRangesAndGetServers();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,15 +399,15 @@ public void addPool(InetSocketAddress server) {

public void removePool(InetSocketAddress removedServerAddress) {
blacklist.remove(removedServerAddress);
CassandraClientPoolingContainer removedContainer = currentPools.remove(removedServerAddress);
try {
currentPools.get(removedServerAddress).shutdownPooling();
removedContainer.shutdownPooling();
} catch (Exception e) {
log.warn(
"While removing a host ({}) from the pool, we were unable to gently cleanup resources.",
SafeArg.of("removedServerAddress", CassandraLogHelper.host(removedServerAddress)),
e);
}
currentPools.remove(removedServerAddress);
}

public void cacheInitialCassandraHosts() {
Expand Down
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-5882.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: fix
fix:
description: Fixed a race condition where we would potentially attempt to use a
Cassandra client pool that we had already closed.
links:
- https://github.com/palantir/atlasdb/pull/5882

0 comments on commit 4ebeb74

Please sign in to comment.