Skip to content

Discovery.Manager: close sync ch after sender() is stopped - #10218

Closed
littlepangdi wants to merge 1 commit into
prometheus:mainfrom
littlepangdi:discovery-manager-shutdown-ch
Closed

littlepangdi wants to merge 1 commit into
prometheus:mainfrom
littlepangdi:discovery-manager-shutdown-ch

Conversation

@littlepangdi

@littlepangdi littlepangdi commented Jan 28, 2022 •

Copy link
Copy Markdown
Contributor

this PR is to fix #10217 , a possible memory leak when quoating manager.Sync() outside manager's lifecycle
also see more discuss in grafana/loki#5238

There is a great design for this channel——send ops only happens within goroutine of sender(),any other place references the channel is via read-mode, see below :

SyncCh() <-chan map[string][]*targetgroup.Group

so I suggested we can close it after sender() is stopped naturally( in defer process,so there is no worry about sending to a closed channel).

@littlepangdi
littlepangdi force-pushed the discovery-manager-shutdown-ch branch from 8f8ae23 to bd8709b Compare February 28, 2022 03:24
@roidelapluie

roidelapluie commented Mar 8, 2022 •

Copy link
Copy Markdown
Member

Thank you for your pull request.

I have been investigating this deeply and this change is not good to me:

Prometheus is using this channel into the NotifyManager and the ScrapeManager. Both are reading from this channel. If this channel is closed, they would receive in loops zero-values from that channel.

The Prometheus server is using https://github.com/oklog/run to manage those goroutines. This packages does not guarantee any shutdown order, which means that the chances that Notify/Scrape manager might read un-necessarily zeroed values is not nil, leading to unpredictable result.

Therefore, I'd prefer to stick to the current behavior.

@roidelapluie

Copy link
Copy Markdown
Member

We have looked at this during our bug scrub. To unblock this, can we maybe use a pattern like ts, ok := <- tsets in scrape/manager.go to detect if the channel is closed, and break when it's the case?

@bboreham

Copy link
Copy Markdown
Member

Discussed again at bug-scrub; closing due to lack of progress.
If you would like to come back to it please feel free to reopen or open a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Discovery.Manager not closing syncCh after sending stopped

3 participants