ElementsProject / lightning

Core Lightning — Lightning Network implementation focusing on spec compliance and performance
Other
2.81k stars 889 forks source link

subds: fix case where we keep retrying on EOF. #7661

Closed rustyrussell closed 1 week ago

rustyrussell commented 1 week ago

Our low-level ccan/io IO routines return three values: -1: error. 0: call me again, I'm not finished. 1: I'm done, go onto the next thing.

In the last release, we tweaked the sematics of "-1": we now opportunistically call a routine which returns 0 once more, in case there's more data. We use errno to distinguish between "EAGAIN" which means there wasn't any data, and real errors.

However, if the underlying read() returns 0 (which it does when the peer has closed the other end) the value of errno is UNDEFINED. If it happens to be EAGAIN, we will call it again, rather than closing. This causes us to spin: in particular people reported hsmd consuming 100% of CPU.

The ccan/io read code handled this by setting errno to 0 in this case, but our own wire low-level routines did not.

Fixes: https://github.com/ElementsProject/lightning/issues/7655

ShahanaFarooqui commented 1 week ago

ACK 93b05a4a739705b2c7f64eeeadcac9e21296cc5a