Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix exception in background metrics collection #3996

Merged
merged 2 commits into from
Oct 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3996.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix exception in background metrics collection
8 changes: 6 additions & 2 deletions synapse/metrics/background_process_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,13 @@ def collect(self):
labels=["name"],
)

# We copy the dict so that it doesn't change from underneath us
# We copy the dict so that it doesn't change from underneath us.
# We also copy the process lists as that can also change
with _bg_metrics_lock:
_background_processes_copy = dict(_background_processes)
_background_processes_copy = {
k: list(v)
for k, v in six.iteritems(_background_processes)
Copy link
Member

Choose a reason for hiding this comment

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

what is to say that this will be thread-safe when the loop below was not?

Copy link
Member Author

@erikjohnston erikjohnston Oct 3, 2018

Choose a reason for hiding this comment

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

We're copying the dict and lists from inside a lock?

Copy link
Member

Choose a reason for hiding this comment

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

ffs. I should probably learn to read.

Copy link
Member Author

Choose a reason for hiding this comment

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

Glad I'm not the only one 😀

}

for desc, processes in six.iteritems(_background_processes_copy):
background_process_in_flight_count.add_metric(
Expand Down