Blockstream / greenlight

Build apps using self-custodial lightning nodes in the cloud
https://blockstream.github.io/greenlight/getting-started/
MIT License
109 stars 27 forks source link

Fix shutdown signal handling in signer loop #409

Closed ok300 closed 4 months ago

ok300 commented 4 months ago

This PR is ported from https://github.com/breez/breez-sdk/pull/936

The original PR fixes an issue where signer.run_once can block for up to 10 minutes. This means that, if the signer was recently used, the signer loop would block on this call and disregard the shutdown signal for up to 10 minutes. The fix was to place the entire (inner) signer loop in a tokio::select, next to the shutdown signal handling.

The first part of the signer loop (scheduler initialization and maybe_upgrade) was extracted to a separate method as well. This part is not affected by the shutdown signal.

Note: in our version of the loop, we use wait = false, whereas here it is true. This could mean run_once behaves differently for you and might not block in the first place, but I'm not sure.

cdecker commented 4 months ago

ACK https://github.com/Blockstream/greenlight/pull/409/commits/61346c34a3a751ee7423f146b6e042a9886fcff1

:rocket: