Commit 72464d4
committed
fix(metrics): use weakref in fork handler to allow GC after provider shutdown
os.register_at_fork holds callbacks for the lifetime of the process with
no unregister API. Passing a bound method created a permanent strong
reference chain: fork callback → SynchronousMeasurementConsumer →
_reader_storages → MetricReader → exporter, preventing garbage collection
even after MeterProvider.shutdown().
Replace the bound method with a weakref-based closure so the consumer and
everything it owns can be collected normally. The fork handler is a no-op
once the consumer is gone.
Fixes test_meter_provider_shutdown_cleans_up_successfully.1 parent ce9c6ec commit 72464d4
2 files changed
Lines changed: 13 additions & 3 deletions
File tree
- opentelemetry-sdk
- src/opentelemetry/sdk/metrics/_internal
- tests/metrics
Lines changed: 9 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
71 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
72 | 80 | | |
73 | 81 | | |
74 | 82 | | |
| |||
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
211 | | - | |
212 | | - | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
213 | 215 | | |
214 | 216 | | |
215 | 217 | | |
| |||
0 commit comments