fix: skip writes and still shut down after failed DB manager startup - #4246
Open
arimu1 wants to merge 1 commit into
Open
fix: skip writes and still shut down after failed DB manager startup#4246arimu1 wants to merge 1 commit into
arimu1 wants to merge 1 commit into
Conversation
When startupInternal() fails, AbstractDatabaseManager left running=false but write() still accepted events (often NPEing on unassigned state) and shutdown() skipped shutdownInternal(), leaking resources acquired during startup. Guard write() with isRunning() (log once) and always invoke shutdownInternal() once. Make CassandraManager.shutdownInternal null-safe for a missing session after failed connect. Fixes apache#4241 Signed-off-by: arimu1 <19286898+arimu1@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4241
Description
AbstractDatabaseManagerchecksisRunning()on the shutdown path but not on the write path.After
startupInternal()throws,startup()logs the cause and leavesrunning = false. Then:write()did not check it — kept accepting events and dereferencing state startup never assigned (NPE per event, burying the original cause).shutdown()only ranshutdownInternal()whenrunning— so resources acquired during a failed startup (or in the manager factory) were never released. Returnstrueanyway.This change:
write()return early when!isRunning(), logging a single status warning instead of one failure per event.shutdown()always invokeshutdownInternal()once (tracked independently ofrunning), so partial startup state can be cleaned up.CassandraManager.shutdownInternal()null-safe whensessionwas never created (motivating failure mode from the issue / related log4j-cassandra: failed appender startup leaks the DataStax Cluster, so the JVM never exits #4242).Checklist
2.xbranch if you are targeting Log4j 2; usemainotherwise./mvnw verifysucceeds (the build instructions)src/changelog/.2.x.xdirectoryTesting
[17,18)) — JBR 17.0.14./mvnw test -pl :log4j-core-test -am -Dtest=AbstractDatabaseManagerTest -Dsurefire.failIfNoSpecifiedTests=false— 11/11 passtestFailedStartupSkipsWrite,testFailedStartupStillShutsDown,testShutdownWithoutStartupStillRunsShutdownInternal:log4j-core,:log4j-core-test,:log4j-cassandra