fix: avoid consuming logs after client init failure - #6959
Merged
Conversation
Aias00
approved these changes
Aug 20, 2026
Aias00
left a comment
Contributor
There was a problem hiding this comment.
Summary
Fixes #6846 — logging clients were marked started (isStarted=true) even when initClient0 failed, so consume then touched uninitialized producers/sinks and threw NPEs.
AbstractLogConsumeClient.initClient0return type changed fromvoidtoboolean;initClientnow setsisStartedto the init result and only registers the shutdown hook when initialization succeeded.- All 9 concrete clients (Aliyun SLS, ClickHouse, ElasticSearch, Huawei LTS, Kafka, Pulsar, RabbitMQ, RocketMQ, Tencent CLS) updated: return
falseon blank-config / failure (with best-effortclose0()cleanup where the producer/channel was partially created),trueon success. - Added null guards in
consume0for Kafka (producer), Pulsar (producer), RabbitMQ (channel), RocketMQ (producer), Tencent CLS (client) — skip publishing with a warning instead of NPE. - Pulsar
close0restructured soclient.close()runs even ifproduceris null. - New
AbstractLogConsumeClientTestcovers not-started-skip, started-runs, and failed-reinit leaves client stopped.
Verification
- Compile safety: grepped
extends AbstractLogConsumeClientacross the repo. The only extra match isAbstractLogCollector, which uses it only as a generic type bound (T extends AbstractLogConsumeClient<?, L>) — it does not overrideinitClient0, so no missing override. All 9 real subclasses are in the diff and changed. - Master
initClientalready callsthis.close()whenisStarted.get()before re-init; that "close previous" path is what makestestFailedReinitializationLeavesClientStoppedassertcloseCount==1(init#1 starts, init#2 closes it then fails). Behavior is internally consistent. - Existing
ClickHouseLogCollectClientTest.testConsume/PulsarLogCollectClientTest.testConsumechanged from expecting a thrown exception toassertDoesNotThrow— correct now that a failed init no longer marks the client started.
Conclusion
Correct, well-scoped fix with proper cleanup and good test coverage. Approving.
…rks_started_even_when_initClient0_failed_NPE_in_consume0
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: #6846
Ensure logging clients are marked as started only after successful initialization, preventing log consumption with
uninitialized producers. Add null guards, failure cleanup, and related tests.
Make sure that:
./mvnw clean install -Dmaven.javadoc.skip=true.