-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
PoolTimedOut error with OnceCell due to OnceCell dropped with the test which initialized it #2881
Comments
Enable this will lower the possibility the bug happens, but cannot fix it. PgPoolOptions::new()
.test_before_acquire(false)
.connect(&url); |
I also added this
If the bug happen, nothing printed, if not, "1" printed. Does it means |
I'm sorry, but it's due to I'm using tokio wrong way. Some issue concerned: |
* fix: use blocking relay subscribe everywhere * chore: add Grafana metrics * chore: increase timeouts * chore: log expected tag and topic * chore: switch to prod relay * fix: replication lag * chore: reduce replication lag sleep for now * chore: increase message delivery timeout * fix: update tokio to fix PoolTimedOut errors: launchbadge/sqlx#2881 (comment) * chore: remove test parallel * fix: use relay HTTP client for tests (#316) * fix: use relay HTTP client for tests * fix: run CI when tests are changed
For anyone else coming here: the simplest way to solve this is by setting the async fn new() -> Self {
let max_connections = if cfg!(test) { 1 } else {4 };
let pg = PgPoolOptions::new()
.acquire_timeout(std::time::Duration::from_secs(2))
.max_connections(max_connections )
.connect(PG_URL)
.await
.unwrap();
Self { pg }
} I am not entirely sure what causes this to fix it but I found it solved by this commit in a tutorial. |
I have put the reason and fixing method here |
Bug Description
I put
PgPool
in aModelManager
, so that I can manage it conveniently. Then I init it usingtokio::sync::OnceCell
, so that all the test func use the same ModelManager.And I have 2 tests, one acquire a
PgPool
connection, and another print something through a method onModelManager
.Run test again and again, and about 1/5 tests will fail with error
PoolTimedOut
.Minimal Reproduction
Find the the cause and fix solution here:
https://github.com/kingwingfly/share_runtime_example
For convenient:
Info
rustc --version
: rustc 1.74.0 (79e9716c9 2023-11-13) and rustc 1.76.0-nightly (a57770440 2023-11-16)The text was updated successfully, but these errors were encountered: