Skip to content

fix: Always close database connections #23

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

Merged
merged 2 commits into from
Nov 1, 2024

Conversation

dehaansa
Copy link

@dehaansa dehaansa commented Oct 24, 2024

A user of grafana's alloy agent noticed ( grafana/alloy#1929 ) a goroutine leak when utilizing the postgres exporter with an inaccessible postgres database. This PR appropriately closes any of the database connections that are opened, preventing the leak.

To test, I just ran the exporter using a configuration that was not valid (no postgres running on my machine), and in another terminal curled it repeatedly, monitoring the goroutine count being returned from the prometheus metrics endpoint. Running this test can very quickly show the leak, and that a build from this PR resolves the issue.

DATA_SOURCE_NAME="user=postgres host=/var/run/postgresql/ sslmode=disable" ./postgres_exporter

---

while true; do curl http://localhost:9187/metrics | grep goroutine; done

Copy link
Member

@Dasomeone Dasomeone left a comment

Choose a reason for hiding this comment

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

LGTM, thank you for catching and addressing this @dehaansa!

@Dasomeone Dasomeone merged commit bcc02ce into grafana:master Nov 1, 2024
2 checks passed
@dehaansa dehaansa deleted the fix/close-all-connections branch November 1, 2024 15:05
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.

2 participants