rust_gpiozero icon indicating copy to clipboard operation
rust_gpiozero copied to clipboard

Concurrency Bug causes DoS

Open TheAlgorythm opened this issue 3 years ago • 2 comments

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();
}

TheAlgorythm avatar Jul 20 '21 14:07 TheAlgorythm

I investigated the problem and it is somewhere in rppal. See golemparts/rppal#92

TheAlgorythm avatar Jul 24 '21 14:07 TheAlgorythm

Please document that only one interrupt in parallel is possible.

TheAlgorythm avatar Jul 24 '21 15:07 TheAlgorythm