Repository navigation
Cache exception handler lookups instead of re-resolving and contending on every error - #14212
Merged
graemerocher merged 2 commits intoOct 31, 2026
Merged
Conversation
…uals/hashCode and hash the qualifier into BeanCandidateKey
graemerocher
approved these changes
Oct 30, 2026
…e block duplicated from TypeArgumentQualifier
|
graemerocher
deleted the
denis/micronaut-exception-handler-contention-81b1d3
branch
October 31, 2026 09:35
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.



Under concurrent error traffic, threads block in
DefaultBeanContext.findConcreteCandidateon aConcurrentHashMap$TreeBinmonitor, and JFR shows time in recursiveTreeNode.findTreeNodecalls underRequestLifecycle.onErrorNoFilter. This happens even when requests keep raising the same exception types.RequestLifecycle.onErrorNoFilterlooks up the handler with a newQualifiers.byTypeArgumentsClosest(cause.getClass(), Object.class)on every error. Two defects combine:ClosestTypeArgumentQualifierhad noequals/hashCode, so the lookup never hitbeanConcreteCandidateCache. Every error re-ran the candidate search and inserted a new key, pushing other entries out of the 30-entry cache.BeanCandidateKey.hashCode()was the bean type's hash only. AllExceptionHandlerkeys landed in one bin, which treeified. The keys are notComparable, so lookups search the whole tree, and every insert locks that one bin.Changes:
ClosestTypeArgumentQualifiergetsequals/hashCodeover its type arguments, likeTypeArgumentQualifier.BeanCandidateKeyhashes the qualifier together with the bean type.Now each exception type takes one cache entry, and later lookups are lock-free hits. A qualifier that overrides
equalswithouthashCodenow misses the cache. Results stay correct; Micronaut's own qualifiers implement both.BeanConcreteCandidateCacheSpec(repeated lookups keep one entry per exception type; keys with different qualifiers get different hashes) and a newClosestTypeArgumentSpeccase fail without the fix and pass with it.