SAI-6021 : Fix slow node detection metric context leaks#311
Open
patsonluk wants to merge 3 commits intofs/branch_9_7from
Open
SAI-6021 : Fix slow node detection metric context leaks#311patsonluk wants to merge 3 commits intofs/branch_9_7from
patsonluk wants to merge 3 commits intofs/branch_9_7from
Conversation
solr/core/src/java/org/apache/solr/handler/component/SlowNodeDetector.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| @Override | ||
| public SolrMetricsContext getSolrMetricsContext() { // using the same context as parent | ||
| return null; | ||
| return metricsContext; |
There was a problem hiding this comment.
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.
Description
There are 2 potential
SolrMetricsContextLeak(1 discovered by AI and another by @magibney, assuming he's not AI 🤖 )TimeLimitingHttpShardHandlerFactory#initializeMetricscalls bothsuper.initializeMetrics(parentContext, scope);ANDsolrMetricsContext = parentContext.getChildContext(this);. Both calls create new metrics, but only the latter one got closed via theSolrMetricProducer.super.close()SlowNodeDetectorregisters gauge metrics viaSolrMetricManagerdirectly and never unregister them. This technically does not cause any leaks (if the parent context is closed properly), however it's probably better to callSolrMetricsContext#gaugemethod instead.In reality this should be rather minimal in impact:
TimeLimitingHttpShardHandlerFactoryandSlowNodeDetector(the core container one is not using the same config, hence not aTimeLimitingHttpShardHandlerFactory).TimeLimitingHttpShardHandlerFactoryis not applied to non QA node (which could have way more cores hence more problematic)TimeLimitingHttpShardHandlerFactoryare only counters. They are likely not an issue for memory as:SolrMetricsContext#unregisteronly unregister gauges and not care about other metrics. My guess is that other metrics are just not a concern?Solution
TimeLimitingHttpShardHandlerFactoryshould no longer callparentContext.getChildContext(this). It should just use the context from its parent classHttpShardHandlerFactory. Remove the overriddengetSolrMetricsContextmethodSlowNodeDetectorwill no longer directly register gauges via the manager, it should use the create a child context from the parent context (in this case fromTimeLimitingHttpShardHandlerFactory)'sgaugemethod, which should take care of the gauges on closing. The overriddengetSolrMetricsContextshould return this new child context instead of null. Take note that in theorySlowNodeDetectorcan just use the parent context fromTimeLimitingHttpShardHandlerFactorysince they share the same life cycle (for now). However, I don't really like that coupling, and is probably better oof having its own dedicated contextNote
Low Risk
Primarily refactors metrics registration/cleanup to use
SolrMetricsContextcorrectly and adds explicit close handling; minimal behavioral impact outside metrics lifecycle management.Overview
Fixes potential metrics context leaks in slow-node detection and query shard handling.
TimeLimitingHttpShardHandlerFactorynow uses the metrics context created byHttpShardHandlerFactory(removing its extra child context) and ensuresSlowNodeDetectoris closed during factory shutdown.SlowNodeDetectorswitches from directSolrMetricManager.registerGaugecalls to a dedicated childSolrMetricsContextwithgauge(...), and returns that context viagetSolrMetricsContext()so gauges are properly unregistered on close.Written by Cursor Bugbot for commit 9983ffc. This will update automatically on new commits. Configure here.