Skip to content

Commit 76223cd

Browse files
committed
probe: clean-up database connection after probe to prevent connection leak
Signed-off-by: Kurtis Bass <[email protected]>
1 parent 9bd9d83 commit 76223cd

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

cmd/postgres_exporter/probe.go

+3
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ func handleProbe(logger log.Logger) http.HandlerFunc {
104104
return
105105
}
106106

107+
// Cleanup underlying connections to prevent connection leaks
108+
defer pc.Close()
109+
107110
// TODO(@sysadmind): Remove the registry.MustRegister() call below and instead handle the collection here. That will allow
108111
// for the passing of context, handling of timeouts, and more control over the collection.
109112
// The current NewProbeCollector() implementation relies on the MustNewConstMetric() call to create the metrics which is not

collector/probe.go

+4
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,7 @@ func (pc *ProbeCollector) Collect(ch chan<- prometheus.Metric) {
8383
}
8484
wg.Wait()
8585
}
86+
87+
func (pc *ProbeCollector) Close() error {
88+
return pc.db.Close()
89+
}

0 commit comments

Comments
 (0)