Skip to content

Fix NPE when closing a pool during initialization#864

Open
dkropachev wants to merge 1 commit intoscylladb:scylla-3.xfrom
dkropachev:fix/issue-85-pool-close-race
Open

Fix NPE when closing a pool during initialization#864
dkropachev wants to merge 1 commit intoscylladb:scylla-3.xfrom
dkropachev:fix/issue-85-pool-close-race

Conversation

@dkropachev
Copy link
Copy Markdown

@dkropachev dkropachev commented Apr 9, 2026

Summary

Users reported the following failure during pool teardown:

java.lang.NullPointerException: Cannot read the array length because "<local2>" is null

at com.datastax.cql3.scylla_shaded.driver.core.HostConnectionPool.closeAsync(HostConnectionPool.java:841).

This change:

  • makes HostConnectionPool.closeAsync() tolerate pools that are still uninitialized or only partially initialized
  • avoids publishing partially built shard arrays while initialization is still setting them up
  • adds a regression test that closes an uninitialized pool and verifies shutdown completes cleanly

Testing

  • mvn -pl driver-core -Dtest=HostConnectionPoolTest#should_close_uninitialized_pool_without_npe test

Fixes #85.

@dkropachev dkropachev requested a review from nikagra April 9, 2026 18:56
@dkropachev dkropachev marked this pull request as ready for review April 9, 2026 18:57
Comment on lines +317 to +321
this.connections = connectionsByShard;
scheduledForCreation = scheduledForCreationByShard;
open = openByShard;
trash = trashByShard;
pendingBorrows = pendingBorrowsByShard;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Race window still remains which may cause a partial initialization.

public void onFailure(Throwable t) {
phase.compareAndSet(Phase.INITIALIZING, Phase.INIT_FAILED);
forceClose(connections);
for (List<Connection> shardConnections : HostConnectionPool.this.connections) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to Claude there is a chance connections can be null here, hardening recommended

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants