Skip to content

Commit e4f1a43

Browse files
authored
[receiver/prometheus] fix panic on shutdown (#16470)
1 parent 8ecca6a commit e4f1a43

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: bug_fix
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
5+
component: prometheusreceiver
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: "Fix prometheus receiver panic on shutdown"
9+
10+
# One or more tracking issues related to the change
11+
issues: [16469]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext:

receiver/prometheusreceiver/metrics_receiver.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,12 @@ func gcInterval(cfg *config.Config) time.Duration {
312312

313313
// Shutdown stops and cancels the underlying Prometheus scrapers.
314314
func (r *pReceiver) Shutdown(context.Context) error {
315-
r.cancelFunc()
316-
r.scrapeManager.Stop()
315+
if r.cancelFunc != nil {
316+
r.cancelFunc()
317+
}
318+
if r.scrapeManager != nil {
319+
r.scrapeManager.Stop()
320+
}
317321
close(r.targetAllocatorStop)
318322
return nil
319323
}

0 commit comments

Comments
 (0)