Repository navigation
Remember that a connections probe was disabled - #3732
Merged
nicolargo merged 1 commit intoSep 12, 2026
Merged
Conversation
The connections plugin gives up on a probe that fails: psutil.net_connections
raising, or the nf_conntrack files not being there. It records that by
writing net_connections_enabled / nf_conntrack_enabled into stats, but
update() starts every refresh with
stats = self.get_init_value()
which is a copy of stats_init_value, where both flags are True. The flag is
therefore forgotten as soon as it is written, and update() calls the failing
probe again on the next refresh. Measured with the conntrack path pointing at
a missing file and three refreshes: three reads and three
"Can not get network connections track" warnings, instead of one.
That also defeats the guard around psutil.net_connections, which is the
expensive call the plugin's own comment is about ("because it consumes lots
of CPU"), on a host where it raises, such as macOS without root.
Keep the two flags on the plugin, the way mem keeps zfs_enabled and sensors
keeps its probe state, and copy them into stats each refresh so the views and
the REST API still see them.
Owner
|
Thanks @datrixlab Merged into develop. |
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
The connections plugin stops using a probe that fails —
psutil.net_connections()raising, or thenf_conntrackfiles not being present — and records that by writingnet_connections_enabled/nf_conntrack_enabledintostats.But
update()starts every refresh withstats = self.get_init_value(), which iscopy.copy(self.stats_init_value), andstats_init_valuehas both flagsTrue(glances/plugins/connections/__init__.py:98). The flag is written into a dict that is thrown away at the end of the refresh, and the next refresh calls the failing probe again.Measured by pointing
conntrackat a file that does not exist and refreshing three times:So on any host without
/proc/sys/net/netfilter/nf_conntrack_*— macOS, Windows, a Linux kernel without the module — the warning plus itsDisable connections trackinfo line are logged on every single refresh.The same applies to the
psutil.net_connections()guard, and that one matters beyond the log: the plugin is disabled by default "because it consumes lots of CPU", so a user who turns it on (config or theKkey) on a host where the call raises, such as macOS without root, pays for the failing call every refresh.Every other plugin that gives up keeps the flag outside the per-refresh stats:
memwithself.zfs_enabled(mem/__init__.py:134, read at:180),sensorswith its grabber'sinitflag,wifiwith a module-level check.Resume
net_connections_enabled/nf_conntrack_enabledon the plugin instance, set toFalsethe first time a probe fails.statsat the start of each refresh, soupdate_views(),msg_curse()and the REST/WebUI payload still carry the same two fields as before.Tests in
tests/test_connections_states.py:Falsepsutil.net_connectionsis called once across three refreshesnf_conntrack_percentis still computedThe tests drive the real
update()with the refresh timer pushed past its deadline between calls, the way the main loop reaches it; without that, the refresh timer alone would make any version of the code look correct.With
glances/plugins/connections/__init__.pyreverted, the first two fail (3 reads / 3 calls instead of 1) and the guard passes.pytest tests/test_connections_states.py tests/test_core.py tests/test_plugin_ports.py→ 75 passed, 6 skipped.ruff checkandruff format --checkclean.Fixed tickets
None open; I did not find an issue for this.