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

Flaky (Deadlock Detected) krate tests. #4729

Closed
adsnaider opened this issue Apr 15, 2022 · 3 comments
Closed

Flaky (Deadlock Detected) krate tests. #4729

adsnaider opened this issue Apr 15, 2022 · 3 comments
Labels
A-backend ⚙️ C-internal 🔧 Category: Nonessential work that would make the codebase more consistent or clear

Comments

@adsnaider
Copy link

Current Behavior

While contributing to crates.io for #4690, I got failures from some krate tests during development. I reran the tests and the failures were gone. I figured I would post the issue so that we have a record of this behavior.

Here's the test output I got. However, it's hard to reproduce since there seems to be some flakiness.

failures:

---- krate::show::show_minimal stdout ----
thread 'krate::show::show_minimal' panicked at 'Unable to create crate foo_show_minimal: DatabaseError(__Unknown, "deadlock detected")', src/tests/builders/krate.rs:181:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- krate::summary::excluded_crate_id stdout ----
thread 'krate::summary::excluded_crate_id' panicked at 'Unable to create crate some_downloads: DatabaseError(__Unknown, "deadlock detected")', src/tests/builders/krate.rs:181:13

---- krate::search::index_queries stdout ----
thread 'krate::search::index_queries' panicked at 'called `Result::unwrap()` on an `Err` value: DatabaseError(__Unknown, "deadlock detected")', src/tests/krate/search.rs:85:14


failures:
    krate::search::index_queries
    krate::show::show_minimal
    krate::summary::excluded_crate_id

test result: FAILED. 253 passed; 3 failed; 0 ignored; 0 measured; 0 filtered out; finished in 14.26s

Expected Behavior

Tests are deterministic.

Steps To Reproduce

cargo test and hope for the worst.

Environment

  • Browser: N/A (backend issue only)
  • OS: PopOS 21.04

Anything else?

No response

@adsnaider adsnaider added the C-bug 🐞 Category: unintended, undesired behavior label Apr 15, 2022
@Turbo87 Turbo87 added C-internal 🔧 Category: Nonessential work that would make the codebase more consistent or clear A-backend ⚙️ and removed C-bug 🐞 Category: unintended, undesired behavior labels Apr 16, 2022
@Turbo87
Copy link
Member

Turbo87 commented May 20, 2022

I've seen similar things before when developing locally, but interestingly I've never observed this on CI. any clues what might be causing this? I'm wondering if it might be caused by a Postgres bug, rather than something wrong on our side.

@pietroalbini
Copy link
Member

That depends on the amount of parallel tests you run: if you set a low concurrency (CI runs two tests at the time) you'll basically never see the error, while if you have a high concurrency (like 16 in parallel) you'll likely see one every time.

This is due to all tests operating on the same empty database inside their own transactions (rolled back when the test finishes): when two tests change the same table one of them will lock it, and in some cases there is some combinations of locks resulting in a deadlock.

@Turbo87
Copy link
Member

Turbo87 commented Feb 12, 2024

Since the issue was opened we switched to a system where each test gets its own fresh database, so the problem should hopefully be resolved now :)

@Turbo87 Turbo87 closed this as completed Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-backend ⚙️ C-internal 🔧 Category: Nonessential work that would make the codebase more consistent or clear
Projects
None yet
Development

No branches or pull requests

3 participants