I'm experiencing intermittent but fairly frequent 'Permission denied' (EACCES) errors in gpio.setup() on my Raspberry Pi Zero W. My program is running as the default 'pi' user on Rasbian 10 (buster). The pi user is a member of the 'gpio' group.
I suspect that the race is more of an issue on slower hardware like the Pi Zero. This small test program usually reproduces the issue for me fairly quickly:
const gpio = require('rpi-gpio');
const PIN_MODE = gpio.MODE_BCM;
const PINS = [2, 3, 4, 14, 15, 17, 18, 27, 22];
function setup() {
gpio.setMode(PIN_MODE);
for (const pin of PINS) {
// This can sometimes thrown an 'EACCES: permission denied' error
gpio.setup(pin, gpio.DIR_OUT, function (error) {
if (error) {
console.log('Setup error:', error);
process.exit();
} else {
console.log('Setup pin', pin);
}
});
}
}
setup();
I'm experiencing intermittent but fairly frequent 'Permission denied' (EACCES) errors in gpio.setup() on my Raspberry Pi Zero W. My program is running as the default 'pi' user on Rasbian 10 (buster). The pi user is a member of the 'gpio' group.
The failure is always the fs.openSync() call in listen(). listen() is called immediately after setDirection(), which makes me think we're hitting the race against udev described here: https://stackoverflow.com/questions/39524234/bug-with-writing-to-file-in-linux-sys-class-gpio
I suspect that the race is more of an issue on slower hardware like the Pi Zero. This small test program usually reproduces the issue for me fairly quickly:
Output:
Adding retry logic to the call to listen works around the problem for me. I'll put up a PR with my fix.