Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.0] only register prometheus handlers when prometheus_plugin enabled; fixing memory leak #2038

Merged
merged 3 commits into from
Jan 4, 2024

Conversation

spoonincode
Copy link
Member

appbase plugins are constructed no matter if they are enabled or not. This meant no matter whether the prometheus_plugin was enabled it would install its handlers in to http_plugin, net_plugin, etc. These handlers always post() to prometheus_plugin's strand. But when prometheus_plugin isn't enabled its strand is never serviced leading to an endlessly growing queue that is never drained. Each HTTP request would add on to this queue, for example.

Move the handler registration to plugin_initialize() so handlers will only be registered when the plugin is enabled ergo when the strand will be pumped. (this is actually how it was prior to #1074, which makes me wonder if there was a need for this change, but I am not immediately seeing one)

Resolves #2030

@@ -4597,7 +4597,6 @@ namespace eosio {
// called from any thread
void connections_manager::start_conn_timers() {
start_conn_timer(connector_period, {}, timer_type::check); // this locks mutex
start_conn_timer(connector_period, {}, timer_type::stats); // this locks mutex
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this was mistakenly left in during some sort of refactor? connection_statistics_monitor() is clearly only valid when update_p2p_connection_metrics is a valid function (it even assert()s on it). I thought maybe connection_statistics_monitor() drives some other non-prometheus statistics when prometheus isn't enabled, but it doesn't seem so.

@@ -4597,7 +4597,6 @@ namespace eosio {
// called from any thread
void connections_manager::start_conn_timers() {
start_conn_timer(connector_period, {}, timer_type::check); // this locks mutex
start_conn_timer(connector_period, {}, timer_type::stats); // this locks mutex
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this line is removed, won't it prevent the prometheus net_plugin stats from being updated, even if the prometheus plugin is enabled?
Unless I missed some other piece of code calling connections_manager::connection_statistics_monitor, but I didn't find any.
Maybe we should just have that function return immediately if update_p2p_connection_metrics is empty?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the next line below.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I missed that, thanks Kevin.
I think it would be safer to check for !!update_p2p_connection_metrics inside connection_statistics_monitor rather than at the calling site, but I guess it works as is.

@spoonincode spoonincode merged commit 31f7bc4 into release/5.0 Jan 4, 2024
29 checks passed
@spoonincode spoonincode deleted the prom_handler_fix_50 branch January 4, 2024 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants