From 18a4871db891d2ad49a498812fc07000c3cb2e58 Mon Sep 17 00:00:00 2001 From: Eitan Seri-Levi Date: Tue, 7 Jan 2025 19:00:57 +0700 Subject: [PATCH 1/8] Add lockbud to CI --- .github/workflows/test-suite.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/test-suite.yml b/.github/workflows/test-suite.yml index cbce0ab1f..bb213a9ed 100644 --- a/.github/workflows/test-suite.yml +++ b/.github/workflows/test-suite.yml @@ -210,3 +210,17 @@ jobs: bins: cargo-sort - name: Run cargo sort to check if Cargo.toml files are sorted run: cargo sort --check --workspace + + lockbud: + name: lockbud + runs-on: ubuntu-latest + container: + image: sigmaprime/lockbud:latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Install dependencies + run: apt update && apt install -y cmake libclang-dev + - name: Check for deadlocks + run: | + cargo lockbud -k deadlock -b -l tokio_util From ca9d0ff53c465f6b3593bbf808dc2d95c3e93b6d Mon Sep 17 00:00:00 2001 From: Daniel Knopik Date: Thu, 16 Jan 2025 11:00:37 +0100 Subject: [PATCH 2/8] add deadlock :troll-parrot: --- anchor/src/main.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/anchor/src/main.rs b/anchor/src/main.rs index 6b632ecf5..41e6b2506 100644 --- a/anchor/src/main.rs +++ b/anchor/src/main.rs @@ -8,6 +8,20 @@ use task_executor::ShutdownReason; use types::MainnetEthSpec; fn main() { + let data = std::sync::Arc::new(std::sync::RwLock::new(1)); + let data2 = std::sync::Arc::clone(&data); + let th = std::thread::spawn(move || { + let a = data.read().unwrap(); // First read lock + println!("read {}", a); + std::thread::sleep(std::time::Duration::from_millis(200)); + let b = data.read().unwrap(); // Second read lock + println!("read {}", b); + }); + std::thread::sleep(std::time::Duration::from_millis(100)); + *data2.write().unwrap() = 2; // write lock in between + println!("done"); + let _ = th.join(); + // Enable backtraces unless a RUST_BACKTRACE value has already been explicitly provided. if std::env::var("RUST_BACKTRACE").is_err() { std::env::set_var("RUST_BACKTRACE", "1"); From 09715ecde0a5e6a75e2c2aea8319f69d73c8df8c Mon Sep 17 00:00:00 2001 From: Daniel Knopik Date: Thu, 16 Jan 2025 11:01:57 +0100 Subject: [PATCH 3/8] cargo fmt --- anchor/src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/anchor/src/main.rs b/anchor/src/main.rs index 41e6b2506..a0eae0e92 100644 --- a/anchor/src/main.rs +++ b/anchor/src/main.rs @@ -11,14 +11,14 @@ fn main() { let data = std::sync::Arc::new(std::sync::RwLock::new(1)); let data2 = std::sync::Arc::clone(&data); let th = std::thread::spawn(move || { - let a = data.read().unwrap(); // First read lock + let a = data.read().unwrap(); // First read lock println!("read {}", a); std::thread::sleep(std::time::Duration::from_millis(200)); - let b = data.read().unwrap(); // Second read lock + let b = data.read().unwrap(); // Second read lock println!("read {}", b); }); std::thread::sleep(std::time::Duration::from_millis(100)); - *data2.write().unwrap() = 2; // write lock in between + *data2.write().unwrap() = 2; // write lock in between println!("done"); let _ = th.join(); From e623a60ccce0cc3810077a10cd0b556df1822a91 Mon Sep 17 00:00:00 2001 From: Anton Hughes Date: Mon, 20 Jan 2025 10:31:24 +1300 Subject: [PATCH 4/8] Add script to check for deadlocks using Lockbud --- .github/scripts/check_lockbud.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 .github/scripts/check_lockbud.sh diff --git a/.github/scripts/check_lockbud.sh b/.github/scripts/check_lockbud.sh new file mode 100755 index 000000000..c21f347ee --- /dev/null +++ b/.github/scripts/check_lockbud.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# Run lockbud to check for deadlocks and capture the output +output=$(cargo lockbud -k deadlock -b -l tokio_util) + +# Check if lockbud returned any issues +if [[ -n "$output" ]]; then + # Print the JSON payload + echo "Lockbud detected issues:" + echo "$output" + + # Exit with a non-zero status to indicate an error + exit 1 +else + echo "No issues detected by Lockbud." + exit 0 +fi \ No newline at end of file From 53bb322fdcaf7cad0c283921d129e180566843ae Mon Sep 17 00:00:00 2001 From: Anton Hughes Date: Mon, 20 Jan 2025 10:31:35 +1300 Subject: [PATCH 5/8] Update test suite to use external script for deadlock checks --- .github/workflows/test-suite.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test-suite.yml b/.github/workflows/test-suite.yml index 1323b2d2d..b3c6e8859 100644 --- a/.github/workflows/test-suite.yml +++ b/.github/workflows/test-suite.yml @@ -225,5 +225,4 @@ jobs: - name: Install dependencies run: apt update && apt install -y cmake libclang-dev - name: Check for deadlocks - run: | - cargo lockbud -k deadlock -b -l tokio_util + run: .github/scripts/check_lockbud.sh From 29cbbcc47a28d5a6b76c79f52d61a1660946479b Mon Sep 17 00:00:00 2001 From: Anton Hughes Date: Mon, 20 Jan 2025 10:54:11 +1300 Subject: [PATCH 6/8] grep output from lockbud --- .github/scripts/check_lockbud.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/scripts/check_lockbud.sh b/.github/scripts/check_lockbud.sh index c21f347ee..ca6af6c7a 100755 --- a/.github/scripts/check_lockbud.sh +++ b/.github/scripts/check_lockbud.sh @@ -1,10 +1,10 @@ #!/bin/bash # Run lockbud to check for deadlocks and capture the output -output=$(cargo lockbud -k deadlock -b -l tokio_util) +output=$(cargo lockbud -k deadlock -b -l tokio_util 2>&1) # Check if lockbud returned any issues -if [[ -n "$output" ]]; then +if echo "$output" | grep -q '"bug_kind"'; then # Print the JSON payload echo "Lockbud detected issues:" echo "$output" From d07151b1c08be81797357b10809081c6ecbd19d7 Mon Sep 17 00:00:00 2001 From: Anton Hughes Date: Wed, 22 Jan 2025 12:22:01 +1300 Subject: [PATCH 7/8] remove example locking code --- anchor/src/main.rs | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/anchor/src/main.rs b/anchor/src/main.rs index a0eae0e92..e9aa28ebf 100644 --- a/anchor/src/main.rs +++ b/anchor/src/main.rs @@ -8,20 +8,6 @@ use task_executor::ShutdownReason; use types::MainnetEthSpec; fn main() { - let data = std::sync::Arc::new(std::sync::RwLock::new(1)); - let data2 = std::sync::Arc::clone(&data); - let th = std::thread::spawn(move || { - let a = data.read().unwrap(); // First read lock - println!("read {}", a); - std::thread::sleep(std::time::Duration::from_millis(200)); - let b = data.read().unwrap(); // Second read lock - println!("read {}", b); - }); - std::thread::sleep(std::time::Duration::from_millis(100)); - *data2.write().unwrap() = 2; // write lock in between - println!("done"); - let _ = th.join(); - // Enable backtraces unless a RUST_BACKTRACE value has already been explicitly provided. if std::env::var("RUST_BACKTRACE").is_err() { std::env::set_var("RUST_BACKTRACE", "1"); @@ -87,4 +73,4 @@ fn main() { error!(reason = msg.to_string(), "Failed to shutdown gracefully"); } }; -} +} \ No newline at end of file From 0e28fe1e24b92b521ae373f5f811d286b4f1713e Mon Sep 17 00:00:00 2001 From: Daniel Knopik Date: Wed, 22 Jan 2025 08:25:37 +0100 Subject: [PATCH 8/8] cargo fmt --- anchor/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anchor/src/main.rs b/anchor/src/main.rs index e9aa28ebf..6b632ecf5 100644 --- a/anchor/src/main.rs +++ b/anchor/src/main.rs @@ -73,4 +73,4 @@ fn main() { error!(reason = msg.to_string(), "Failed to shutdown gracefully"); } }; -} \ No newline at end of file +}