Skip to content

Conversation

@swlynch99
Copy link
Contributor

Once a connection to the database is lost all future macro evaluations will fail. This is fine for normal compilation since it tends to be short but causes issues with rust-analyzer since it keeps the macro binaries loaded for a long time.

This commit changes the macro implementation to drop the cached connection when it encounters an IO or protocol error. In practice these seem to be the errors that show up when the connection is lost and dumping the connection on every error would have unnecessary overhead.

I haven't included any tests cases here because I actually have no idea how to write a test case for this. I have tested it manually though and it works as expected.

Does your PR solve an issue?

Fixes #3939

Is this a breaking change?

No.

Once a connection to the database is lost all future macro evaluations
will fail. This is fine for normal compilation since it tends to be
short but causes issues with rust-analyzer since it keeps the macro
binaries loaded for a long time.

This commit changes the macro implementation to drop the cached
connection when it encounters an IO or protocol error. In practice these
seem to be the errors that show up when the connection is lost and
dumping the connection on every error would have unnecessary overhead.
@abonander abonander merged commit 69bb595 into launchbadge:main Aug 29, 2025
104 checks passed
@swlynch99 swlynch99 deleted the drop-conn-on-error branch August 29, 2025 07:30
JosiahParry pushed a commit to JosiahParry/sqlx that referenced this pull request Sep 24, 2025
…ge#4009)

Once a connection to the database is lost all future macro evaluations
will fail. This is fine for normal compilation since it tends to be
short but causes issues with rust-analyzer since it keeps the macro
binaries loaded for a long time.

This commit changes the macro implementation to drop the cached
connection when it encounters an IO or protocol error. In practice these
seem to be the errors that show up when the connection is lost and
dumping the connection on every error would have unnecessary overhead.
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.

Losing connection to the database results in query! macros returning errors permanently in rust-analyzer

2 participants