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

fix: implement InstanceDisposer to close db connections #136

Merged
merged 2 commits into from
Oct 1, 2024

Conversation

njvrzm
Copy link
Contributor

@njvrzm njvrzm commented Sep 30, 2024

This adds support for the InstanceDisposer() interface to SQLDatasource, to fix a connection leak.

Fixes #135

@njvrzm njvrzm self-assigned this Sep 30, 2024
@njvrzm njvrzm marked this pull request as ready for review September 30, 2024 19:10
@njvrzm njvrzm requested a review from a team as a code owner September 30, 2024 19:10
ds.Dispose()
count := 0
conn.connections.Range(func(key, value interface{}) bool {
count++
return true
})
if count != 2 {
t.Errorf("missing connections")
if count != 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we know why this was originally checking that we don't delete connections?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't! Except that, of course, it originally didn't. I suppose it's possible that existing datasources are relying on that behavior, if their connectors reuse connections? But I feel like that would be a bit weird, and it doesn't look like any of ours do that.

You could argue that this should be a new major version, but to me this feels more like a bugfix than a backwards incompatible change, even if the bug was originally intentional. If that makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(Fwiw I looked over the datasources - grafana and non-grafana - using sqlds.NewDatasource and it doesn't look like any of them reuse connections this way.)

Copy link

@aangelisc aangelisc left a comment

Choose a reason for hiding this comment

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

The change looks good to me. I'm a little surprised that we weren't actually closing the connections before 🤔 I would suggest releasing this as a major because it is a functionality change. I agree that it does seem like a bugfix also but we can't guarantee that any community plugins (if there are any) based on SQLds don't reuse connections in an unexpected fashion.

@njvrzm
Copy link
Contributor Author

njvrzm commented Oct 1, 2024

Fair enough - I looked over the github projects using it (only a handful outside of grafana) but github isn't the whole universe. I feel a little weird bumping to v5 just a couple months after v4, but so it goes :)

@njvrzm njvrzm merged commit 0b49f12 into main Oct 1, 2024
3 checks passed
@njvrzm njvrzm deleted the njvrzm/implement_instance_disposer branch October 1, 2024 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Database connections are not closed when a new datasource is created
3 participants