1
0
mirror of https://github.com/prometheus-community/postgres_exporter.git synced 2025-12-21 04:00:58 +03:00

Ensure database connections are always closed (#1177)

Signed-off-by: Sam DeHaan <sam.dehaan@grafana.com>
Signed-off-by: Sam DeHaan <dehaansa@gmail.com>
Co-authored-by: Sam DeHaan <sam.dehaan@grafana.com>
Co-authored-by: Sam DeHaan <dehaansa@gmail.com>
This commit is contained in:
Cristian Greco
2025-07-18 20:53:45 +02:00
committed by GitHub
parent aa98bb30ef
commit 06a553c816
3 changed files with 7 additions and 2 deletions

View File

@@ -76,11 +76,11 @@ func (pc *ProbeCollector) Describe(ch chan<- *prometheus.Desc) {
func (pc *ProbeCollector) Collect(ch chan<- prometheus.Metric) {
// Set up the database connection for the collector.
err := pc.instance.setup()
defer pc.instance.Close()
if err != nil {
pc.logger.Error("Error opening connection to database", "err", err)
return
}
defer pc.instance.Close()
wg := sync.WaitGroup{}
wg.Add(len(pc.collectors))