Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,10 @@ protected enum State {
private final AuthenticationHelper authHelper = new AuthenticationHelper();

void removeCnxn(ServerCnxn cnxn) {
zkDb.removeCnxn(cnxn);
ZKDatabase db = zkDb;
if (db != null) {
db.removeCnxn(cnxn);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,14 @@ public void testUpdateQuotaExceededMetrics() {
public void testUpdateQuotaExceededMetrics_nullNamespace() {
assertDoesNotThrow(() -> ZooKeeperServer.updateQuotaExceededMetrics(null));
}

@Test
public void testRemoveCnxnBeforeStartData() {
// Simulate a connection cleanup triggered before the server has fully started.
// During this phase zkDb is still null (before startdata()).
// 4-letter commands can hit this path.
ZooKeeperServer zks = new ZooKeeperServer();
ServerCnxn cnxn = mock(ServerCnxn.class);
assertDoesNotThrow(() -> zks.removeCnxn(cnxn));
}
}