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

Cannot close DatabaseConnection by reference #2510

Open
bragov4ik opened this issue Feb 24, 2025 · 1 comment · May be fixed by #2511
Open

Cannot close DatabaseConnection by reference #2510

bragov4ik opened this issue Feb 24, 2025 · 1 comment · May be fixed by #2511

Comments

@bragov4ik
Copy link

Description

Hi, so I use a DatabaseConnection in my service that is shared across different tasks by reference (Arc, in particular). I've recently encountered a problem similar to this (https://discord.com/channels/873880840487206962/1059720897939918878) and I need to manually close the connection.

However, I can't just easily do this because close requires an owned value. Also, I've noticed that all branches of close actually just need a reference (if traced to sqlx). So, I think it makes sense to update the implementation to &self instead, considering that other 'write' operations (to the db) are performed by reference and this is the way sqlx does it.

Steps to Reproduce

Arc::new(connection).close().await;

Workarounds

I know that under the hood the sqlx pools have Arc, so it makes sense to try and use owned value (with cloneing as needed). However, it all breaks once mock feature is enabled. I don't want to restrict the usage of mock.

Versions

latest

@bragov4ik bragov4ik linked a pull request Feb 24, 2025 that will close this issue
2 tasks
@bragov4ik
Copy link
Author

I've linked a PR with what I expect

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 a pull request may close this issue.

1 participant