Export preparation mutates live plugin statistics and contaminates shared snapshots
Check the bug
I searched the repository’s existing issues, pull requests, and discussions and did not find an existing report or merged fix for this exact mutation.
Describe the bug
Export preparation mutates the live statistics objects owned by plugins.
GlancesStats.getAllExports() and GlancesStats.getAllExportsAsDict() return the objects provided by each plugin’s get_export() method without copying them. Exporters subsequently modify those objects in place while merging limit fields and removing <plugin>_disable fields.
Because APIs, UIs, and other exporters may read the same objects, clients can observe exporter-only limit fields, missing disable fields, or changes made by another concurrent exporter.
Affected paths include:
glances/stats.pyglances/exports/export.pyglances/exports/glances_timescaledb/__init__.pyglances/exports/glances_duckdb/__init__.pyglances/exports/glances_clickhouse/__init__.py
To Reproduce
Steps to reproduce the behavior:
Use a plugin whose
get_export()method returns its live statistics dictionary:live_stats = {"total": 12, "user": 7} limits = {"cpu_warning": 70, "cpu_disable": False}Retrieve the plugin through
GlancesStats.getAllExportsAsDict().Run the standard
GlancesExport.update()preparation logic.Inspect
live_statsafter export preparation.Observe that the original dictionary has changed:
{ "total": 12, "user": 7, "cpu_warning": 70, }
The same problem occurs for list-based plugin statistics because each row is updated in place.
A second call to either export getter can also observe changes made through the result of the first call, demonstrating that exporters do not receive isolated snapshots.
Expected behavior
Export preparation should operate on an independent snapshot. It must not modify plugin-owned live statistics or data returned to APIs, UIs, or other exporters.
Each call to getAllExports() or getAllExportsAsDict() should return a fully detached copy, including dictionaries nested inside list-based statistics.
Screenshots
Not applicable.
Environement (please complete the following information)
- Operating System: Linux/WSL; the issue is platform-independent
- Glances & psutil versions: Glances
developatb3f1cf00(4.5.8.dev1) - How do you install Glances: Source checkout
- Glances test: Reproduced with a focused unit test using both dictionary-based and list-based plugin statistics
Additional context Fix in PR #3767
Source: nicolargo/glances