cln-plugin: Ensure we cleanly shut down when we lose the master conn

This commit is contained in:
Christian Decker
2022-02-25 14:55:49 +01:00
committed by Rusty Russell
parent 1bd2b8c9f7
commit 6706384c50

View File

@@ -224,6 +224,9 @@ where
), ),
} }
.run(receiver, input, output), .run(receiver, input, output),
// TODO Use the broadcast to distribute any error that we
// might receive here to anyone listening. (Shutdown
// signal)
); );
Ok(plugin) Ok(plugin)
@@ -362,9 +365,20 @@ where
O: Send + AsyncWriteExt + Unpin, O: Send + AsyncWriteExt + Unpin,
{ {
loop { loop {
// If we encounter any error reading or writing from/to
// the master we hand them up, so we can return control to
// the user-code, which may require some cleanups or
// similar.
tokio::select! { tokio::select! {
_ = self.dispatch_one(&mut input, &self.plugin) => {}, e = self.dispatch_one(&mut input, &self.plugin) => {
v = receiver.recv() => {output.lock().await.send(v.unwrap()).await?}, //Hand any error up.
e?;
},
v = receiver.recv() => {
output.lock().await.send(
v.context("internal communication error")?
).await?;
},
} }
} }
} }
@@ -417,7 +431,7 @@ where
} }
} }
Some(Err(e)) => Err(anyhow!("Error reading command: {}", e)), Some(Err(e)) => Err(anyhow!("Error reading command: {}", e)),
None => Ok(()), None => Err(anyhow!("Error reading from master")),
} }
} }