Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
Commits
032cf84f
Unverified
Commit
032cf84f
authored
1 year ago
by
Erik Johnston
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Remove a reference cycle in background process (#16314)
parent
7afb5e04
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
changelog.d/16314.misc
+1
-0
1 addition, 0 deletions
changelog.d/16314.misc
synapse/metrics/background_process_metrics.py
+20
-1
20 additions, 1 deletion
synapse/metrics/background_process_metrics.py
with
21 additions
and
1 deletion
changelog.d/16314.misc
0 → 100644
+
1
−
0
View file @
032cf84f
Remove a reference cycle for in background processes.
This diff is collapsed.
Click to expand it.
synapse/metrics/background_process_metrics.py
+
20
−
1
View file @
032cf84f
...
@@ -322,13 +322,21 @@ class BackgroundProcessLoggingContext(LoggingContext):
...
@@ -322,13 +322,21 @@ class BackgroundProcessLoggingContext(LoggingContext):
if
instance_id
is
None
:
if
instance_id
is
None
:
instance_id
=
id
(
self
)
instance_id
=
id
(
self
)
super
().
__init__
(
"
%s-%s
"
%
(
name
,
instance_id
))
super
().
__init__
(
"
%s-%s
"
%
(
name
,
instance_id
))
self
.
_proc
=
_BackgroundProcess
(
name
,
self
)
self
.
_proc
:
Optional
[
_BackgroundProcess
]
=
_BackgroundProcess
(
name
,
self
)
def
start
(
self
,
rusage
:
"
Optional[resource.struct_rusage]
"
)
->
None
:
def
start
(
self
,
rusage
:
"
Optional[resource.struct_rusage]
"
)
->
None
:
"""
Log context has started running (again).
"""
"""
Log context has started running (again).
"""
super
().
start
(
rusage
)
super
().
start
(
rusage
)
if
self
.
_proc
is
None
:
logger
.
error
(
"
Background process re-entered without a proc: %s
"
,
self
.
name
,
stack_info
=
True
,
)
return
# We've become active again so we make sure we're in the list of active
# We've become active again so we make sure we're in the list of active
# procs. (Note that "start" here means we've become active, as opposed
# procs. (Note that "start" here means we've become active, as opposed
# to starting for the first time.)
# to starting for the first time.)
...
@@ -345,6 +353,14 @@ class BackgroundProcessLoggingContext(LoggingContext):
...
@@ -345,6 +353,14 @@ class BackgroundProcessLoggingContext(LoggingContext):
super
().
__exit__
(
type
,
value
,
traceback
)
super
().
__exit__
(
type
,
value
,
traceback
)
if
self
.
_proc
is
None
:
logger
.
error
(
"
Background process exited without a proc: %s
"
,
self
.
name
,
stack_info
=
True
,
)
return
# The background process has finished. We explicitly remove and manually
# The background process has finished. We explicitly remove and manually
# update the metrics here so that if nothing is scraping metrics the set
# update the metrics here so that if nothing is scraping metrics the set
# doesn't infinitely grow.
# doesn't infinitely grow.
...
@@ -352,3 +368,6 @@ class BackgroundProcessLoggingContext(LoggingContext):
...
@@ -352,3 +368,6 @@ class BackgroundProcessLoggingContext(LoggingContext):
_background_processes_active_since_last_scrape
.
discard
(
self
.
_proc
)
_background_processes_active_since_last_scrape
.
discard
(
self
.
_proc
)
self
.
_proc
.
update_metrics
()
self
.
_proc
.
update_metrics
()
# Set proc to None to break the reference cycle.
self
.
_proc
=
None
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment