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

0.7.2 - "failed to close setup connection" in #[sqlx::test] with MySqlPool #2888

Closed
mattgray opened this issue Nov 20, 2023 · 4 comments · Fixed by #3191
Closed

0.7.2 - "failed to close setup connection" in #[sqlx::test] with MySqlPool #2888

mattgray opened this issue Nov 20, 2023 · 4 comments · Fixed by #3191
Labels

Comments

@mattgray
Copy link

mattgray commented Nov 20, 2023

Bug Description

I am intermittently getting a test failure:

failed to close setup connection: Io(Os { code: 57, kind: NotConnected, message: "Socket is not connected" })

when running tests using the #[sqlx::test] macro with a test argument type of MySqlPool. This issues has appeared since upgrading to 0.7.2 - I believe the errors are caused by the changes introduced here #2742.

The error is coming from https://github.com/launchbadge/sqlx/blob/main/sqlx-core/src/testing/mod.rs#L258-L260 - the test setup database connection is already closed by some other task when that code runs. Running with cargo test -- --test-threads=1 prevents the error, implying some race condition, but I cannot explain why the PR I linked to is causing the race, or which task is closing the connection.

Minimal Reproduction

See: https://github.com/mattgray/sqlx-test-0-7-2-issue/blob/main/src/main.rs for a minimal reproduction. The actual codebase where I encountered this runs approximately 20 tests that use sqlx::test.

The issue occurs approximately 1 in 100 test runs that use sqlx::test and MySqlPool. Running cargo test -- --test-threads=1 seems to fix the error.

The error occurs whether or not I am connecting via unix socket DATABASE_URL=mysql://root@localhost/test or TCP on loopback DATABASE_URL=mysql://root@127.0.0.1/test

Info

  • SQLx version: 0.7.2
  • SQLx features enabled: "mysql", "runtime-tokio-rustls"
  • Database server and version: MySQL 8.1.0
  • Operating system: Reproduction tested on MacOS 13.6.1, same issue also occurs in CI which is Linux and MySQL 8
  • rustc --version: rustc 1.74.0 (79e9716c9 2023-11-13)
@mattgray mattgray added the bug label Nov 20, 2023
@svenhuster
Copy link

I'm seeing the same issue intermittently.

  • MacOS: 14.1.2 (23B92)
  • Rust: rustc 1.74.0 (79e9716c9 2023-11-13)
  • MySQL: mysql Ver 8.1.0 for macos14.0 on arm64 (Homebrew)
  • SQLx: 0.7.3
  • SQLx features: "mysql", "runtime-tokio", "chrono", "rust_decimal", "runtime-tokio-rustls"

@ejinotti-mdsol
Copy link

FWIW, getting a very similar error coming from the same lines, but different OS error code:

failed to close setup connection: Io(Os { code: 107, kind: NotConnected, message: "Transport endpoint is not connected" })

This is 100%, not intermittent. Running in Github Actions ubuntu-latest (currently 22.04). Also tried the cargo test -- --test-threads=1 suggested above, but did not fix.

  • SQLx version: 0.7.3
  • SQLx features: "runtime-tokio", "tls-rustls", "mysql", "macros", "time", "migrate"
  • MsSQL: 8.0.36
  • OS: Ubuntu 22.04
  • Rust: 1.76.0

@nextuponstream
Copy link

github action, same thing with postgres https://github.com/nextuponstream/totsugeki/actions/runs/8439727791/job/23114999504#step:5:860

usually, I try to rerun and it "works". I have yet to test the --test-threads=1.

I've seen it happen locally on my popos machine with postgres running as a service

I don't mind that it sometimes fail but it's still annoying to see.

@levkk
Copy link
Contributor

levkk commented Apr 10, 2024

Same here, getting this when calling close on a connection. rustc 1.76.0 (07dca489a 2024-02-04) in a tokio test. FWIW, this only happens with connections using TLS, so might be an issue with rustls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants