{"record":{"id":"b3a4d08258c5116d","repo":"transact-rs/sqlx","slug":"failed-to-close-setup-connection","errorCode":null,"errorMessage":"failed to close setup connection","messagePattern":"failed to close setup connection","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"sqlx-core/src/testing/mod.rs","lineNumber":274,"sourceCode":"        .expect(\"failed to connect to test database\");\n\n    if let Some(migrator) = args.migrator {\n        migrator\n            .run_direct(None, &mut conn, false)\n            .await\n            .expect(\"failed to apply migrations\");\n    }\n\n    for fixture in args.fixtures {\n        (&mut conn)\n            .execute(fixture.contents)\n            .await\n            .unwrap_or_else(|e| panic!(\"failed to apply test fixture {:?}: {:?}\", fixture.path, e));\n    }\n\n    conn.close()\n        .await\n        .expect(\"failed to close setup connection\");\n}\n","sourceCodeStart":256,"sourceCodeEnd":276,"githubUrl":"https://github.com/transact-rs/sqlx/blob/03af8bcc5711a1935580a54bea249c219a0c217d/sqlx-core/src/testing/mod.rs#L256-L276","documentation":"sqlx's test harness (`#[sqlx::test]` setup) applies fixture files to a freshly created test database, then closes the setup connection. This panic fires from `.expect()` on `conn.close()` if the connection fails to close gracefully. It is a post-fixture teardown failure, not a fixture failure.","triggerScenarios":"Calling `setup_test_db` (via `#[sqlx::test]` with fixtures) where the final `conn.close()` returns an Err — typically because the connection was already terminated (server dropped it, network blip, or the fixture code left the connection in a broken state).","commonSituations":"Flaky CI runs against remote/shared MySQL or Postgres servers; server-side idle timeout or max_connections killing the setup connection mid-test; proxy/firewall resetting TCP connections; killing the database container while tests run.","solutions":["Retry the test; if it is flaky, check DB server logs for dropped connections (idle_timeout, max_connections).","Point DATABASE_URL at a local database or increase server-side connection limits/timeouts.","Check network stability (proxies, docker port mappings) between test runner and DB.","Update sqlx; if the close failure is caused by a driver bug, a newer patch release may fix it."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// The harness panics via .expect, so guard at the test level:\n// run flaky tests with a retry wrapper or `cargo test -- --retry` in CI,\n// and verify DB reachability before the suite:\nlet mut conn = MySqlPool::connect(&url).await.expect(\"DB unreachable before tests\");\nconn.close().await; // sanity-check close works","preventionTips":["Run integration tests against a local containerized DB, not a shared remote server","Raise server idle_timeout / max_connections to survive test-suite duration","Avoid proxies/NAT layers that reset idle TCP connections mid-suite"],"tags":["sqlx","testing","connection-close","panic"],"backgroundTag":"connection-closed-unexpectedly","analyzedSha":"03af8bcc5711a1935580a54bea249c219a0c217d","analyzedAt":"2026-09-03T15:01:28.752Z","contentChangedAt":"2026-09-03T15:01:28.752Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}