rust_gpiozero
rust_gpiozero copied to clipboard
Concurrency Bug causes DoS
I am using rust_gpiozero v0.2.1 with an Raspberry Pi 4B and found a situation where the library isn't responding to interrupts. I'm not a 100% sure that it is a concurrency bug, but I was only able to replicate the problem in a concurrent situation. The following minimal reproducible example responds only alternating between the pins and doesn't continue on every falling edge.
use std::thread;
use std::time::Duration;
use rust_gpiozero::input_devices::DigitalInputDevice;
fn event_loop(pin: u8) -> thread::JoinHandle<()> {
thread::spawn(move || {
let mut dev = DigitalInputDevice::new(pin);
println!("init {} done", pin);
let mut counter = 0_usize;
loop {
println!("await {} off {}", pin, counter);
dev.wait_for_inactive(None);
println!("awaited {} off {}", pin, counter);
thread::sleep(Duration::from_millis(100));
counter += 1;
}
})
}
fn main() {
let first_el = event_loop(6);
event_loop(16).join().unwrap();
first_el.join().unwrap();
}
I investigated the problem and it is somewhere in rppal. See golemparts/rppal#92
Please document that only one interrupt in parallel is possible.