Log broker availability events as String messages#36856
Open
kodacme wants to merge 1 commit into
Open
Conversation
Prior to this commit, AbstractBrokerMessageHandler logged the BrokerAvailabilityEvent object directly at INFO level. With a structured JSON logging layout, the event could be serialized as an object rather than via toString(), causing the layout to traverse the event source (a SimpleBrokerMessageHandler) object graph. That graph contains a cyclic reference through the client inbound channel executor's thread factory, which fails serialization at the maximum nesting depth. This commit logs the event's toString() representation instead, keeping the same operational signal while preventing structured logging layouts from traversing framework internals. Signed-off-by: kodacme <kodac.saito@kodac.me>
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.
Overview
AbstractBrokerMessageHandlerlogsBrokerAvailabilityEventdirectly at INFO level when the broker becomes (un)available:With a structured JSON logging layout (e.g. Logstash/ECS encoders backed by Jackson), the logging framework may serialize the event object rather than its
toString(). It then traversesBrokerAvailabilityEvent.getSource(), which is theSimpleBrokerMessageHandleritself.That object graph contains a cyclic reference:
Because the thread factory is a non-static inner class, it keeps an implicit reference back to the enclosing
ThreadPoolTaskExecutor, producing an effectively infinite graph. Jackson aborts at its maximum nesting depth:The application keeps starting, but startup logs are flooded with a very large stack trace, which can hide real problems.
Change
Log the event's
toString()representation instead of the event object, in bothpublishBrokerAvailableEvent()andpublishBrokerUnavailableEvent():BrokerAvailabilityEvent.toString()already produces a concise, safe message, so the operational signal is preserved while structured logging layouts no longer traverse framework internals.Notes
toString()).