sqlx query! and friends macros throw constant connection errors when using Docker
I maintainer di solito rispondono entro 4 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 32/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- docker, postgresql, rust
- Ambito
- databases, developer-experience, tooling
Direzione di ricerca
Reproduce with the given docker-compose Postgres, DATABASE_URL, and sqlx::query! after VS Code Reload Window; the compile-time macros (not the runtime pool) fail with EOF. Look at how query! and related macros open a short-lived connection and any timeout or reuse of that connection. Done when editing a query no longer panics in the IDE while the container stays healthy and cargo still builds.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
I have found these related issues/pull requests
#3939 -- no idea why closed, it is not fixed -- maybe not 100% the same issue, but seems very closely related
Description
Constantly receive:
error communicating with database: expected to read 5 bytes, got 0 bytes at EOF
macro panics in VS Code when editing a query after successful connection to the Docker databsae the first time. The database is still running and there are no connection problems from the app itself. This error only occurs in the IDE on sqlx::query! and related macro calls.
This occurs for me > 95% of the time after the initial load or Developer: Reload Window of the IDE. Even if I leave the file and come back to it, it will have this error.
It is quite likely this could be due to a very flaky, intolerant connection attempt by the sqlx macro with a very short timeout, likely for better performance, but seems no way the user can customize this timeout or its other connection parameters.
Reproduction steps
- Create a sqlx project as usual.
- Set up a docker-compose.yaml as follows:
services:
postgres:
image: postgres:17
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
ports:
- "5432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER}"]
interval: 3s
timeout: 1s
retries: 5
- Place database parameters in your
.envfile. - Add a
DATABASE_URLto your.envfile:
DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:5432/${POSTGRES_DB}
- Use a simple
sqlx::querymacro such as:
#[tokio::main]
async fn main() -> anyhow::Result<()> {
dotenvy::dotenv_override().ok();
...
let pg = build_pg_pool_with_options(
&database_url,
&PgPoolOptions::new().max_connections(10),
&HashMap::new(),
)
.await?;
println!("Connected to database: {}", sanitize_url(&database_url));
...
let mut tx = pg.begin().await?;
sqlx::query!(r#"SELECT now(), 1 as "one""#)
.fetch_optional(&mut *tx)
.await?;
}
- You may or may not have the error on
#[tokio::main]at this point. - Run
Developer: Reload Windowcommand just to be sure. - Note it compiles just fine. If it doesn't connect after the reload, there's something wrong with the
DATABASE_URL, Docker postgres container, or other setup, not sqlx itself. - Now, make a simple change to the same query (don't add a new one):
sqlx::query!(r#"SELECT now(), 2 as "two""#)
.fetch_optional(&mut *tx)
.await?;
- Save.
- ERROR! on
#[tokio::main]:
error communicating with database: expected to read 5 bytes, got 0 bytes at EOF
SQLx version
0.8.5
Enabled SQLx features
["chrono", "json", "postgres", "uuid", "migrate", "runtime-tokio-rustls", "bigdecimal"]
Database server and version
Docker container: PostgreSQL 17.6 (Debian 17.6-2.pgdg13+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 14.2.0-19) 14.2.0, 64-bit
Operating system
Host: macOS 15.6.1, Container: Debian 17.6-2.pgdg13+1
Rust version
rustc 1.92.0-nightly (695857bc3 2025-10-21)
- Lingua principale
- Rust
- Stelle
- 17.5k
- Fork
- 1.7k
- Merge medio
- 3g 17h
- PR unite (30g)
- 11
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di transact-rs/sqlx
-
MySQL: a user without a password is refused when the server switches the auth plugin (empty password scrambled)Forse già presa @lmont19 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
transact-rs/sqlx#4482 ·
I maintainer di solito rispondono entro 4 giorni
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
transact-rs/sqlx#4466 ·
I maintainer di solito rispondono entro 4 giorni
-
MySQL: ENUM and SET columns with a binary collation are named BINARY or CHARForse già presa @CodeMasterXZT l’ha presa 7 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
transact-rs/sqlx#4453 ·
I maintainer di solito rispondono entro 4 giorni
-
Postgres text arrays: a quoted "NULL" element is decoded as SQL NULLForse già presa @MinJaeRun l’ha presa 4 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
transact-rs/sqlx#4452 ·
I maintainer di solito rispondono entro 4 giorni
-
Fetch stream ends after first error using query macrosForse già presa @barry3406 l’ha presa 204 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
transact-rs/sqlx#4126 · 1 commento ·
I maintainer di solito rispondono entro 4 giorni
Tutte le issue di transact-rs/sqlx
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
penso/herdr-gpui#934 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Y-ASLant/ElegantClipboard#178 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
linxiv-dev/linXiv#384 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
priority middle
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
KATO-Hiro/AtCoderClans#12945 ·
I maintainer di solito rispondono entro 1 giorno
-
bug drawings ui
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
userFRM/egui-charts#1595 ·
I maintainer di solito rispondono entro 1 giorno