- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.5k
Description
I have found these related issues/pull requests
Not related to any other issue that I could find. The closest seems to be #3738 but that is definitely a different issue.
Description
sqlx::query! and friends open a single database connection and use that to talk to the database. If that connection goes away then any later macros will error. This is not a problem for regular compilation, but rust-analyzer will keep the macro library loaded indefinitely. Once the connection is lost then the only way to get rid of the errors is to completely restart rust-analyzer.
I think the correct thing to do in this case is to try and reconnect to the database after receiving a connection/protocol error so that the next query, at least, is able to continue working appropriately.
Reproduction steps
- Set up a postgres database.
- Configure sqlx to point to this database.
- Write a query that uses the database. For example,
fn do_query(conn: &mut sqlx::PgConnection) { let _ = sqlx::query!("SELECT * FROM information_schema.tables").fetch_all(conn).await; } 
- Restart the database (or otherwise break the connection)
- Modify the query. You will get the following error
At this point any attempt to run a sqlx query macro will result in this error, regardless of whether the database is reachable or not.error communicating with database: expected to read 5 bytes, got 0 bytes at EOF
SQLx version
v0.8.6
Enabled SQLx features
runtime-tokio-native-tls,postgres,uuid,chrono,json,ipnetwork but I suspect this will happen with any database backend
Database server and version
Postgres 15
Operating system
Linux (within WSL2)
Rust version
rustc 1.90.0-nightly (a00149764 2025-07-14)