Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metrics/influxdb: fix time ticker leaks #26507

Merged
merged 1 commit into from
Jan 17, 2023
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
3 changes: 3 additions & 0 deletions metrics/influxdb/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ func (r *reporter) run() {
intervalTicker := time.NewTicker(r.interval)
pingTicker := time.NewTicker(time.Second * 5)

defer intervalTicker.Stop()
defer pingTicker.Stop()

Comment on lines +104 to +106
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically, you are not wrong. But on the other hand, this method run loops forever -- there is no path in which it exits. So there is no path in which these deferred statements are executed.

One could argue that "if we ever add a return, then this will be a resource leak, and this change is thus good to have".

I don't know, I'll let someone else chime in and see what they think. cc @fjl

(same goes for the other change)

for {
select {
case <-intervalTicker.C:
Expand Down
3 changes: 3 additions & 0 deletions metrics/influxdb/influxdbv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ func (r *v2Reporter) run() {
intervalTicker := time.NewTicker(r.interval)
pingTicker := time.NewTicker(time.Second * 5)

defer intervalTicker.Stop()
defer pingTicker.Stop()

for {
select {
case <-intervalTicker.C:
Expand Down