Skip to content

Commit

Permalink
cln-plugin: Ensure we cleanly shut down when we lose the master conn
Browse files Browse the repository at this point in the history
  • Loading branch information
cdecker committed Feb 25, 2022
1 parent 1626a04 commit dba9dd0
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions plugins/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ where
),
}
.run(receiver, input, output),
// TODO Use the broadcast to distribute any error that we
// might receive here to anyone listening. (Shutdown
// signal)
);

Ok(plugin)
Expand Down Expand Up @@ -362,10 +365,21 @@ where
O: Send + AsyncWriteExt + Unpin,
{
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! {
_ = self.dispatch_one(&mut input, &self.plugin) => {},
v = receiver.recv() => {output.lock().await.send(v.unwrap()).await?},
}
e = self.dispatch_one(&mut input, &self.plugin) => {
//Hand any error up.
e?;
},
v = receiver.recv() => {
output.lock().await.send(
v.context("internal communication error")?
).await?;
},
}
}
}

Expand Down Expand Up @@ -417,7 +431,7 @@ where
}
}
Some(Err(e)) => Err(anyhow!("Error reading command: {}", e)),
None => Ok(()),
None => Err(anyhow!("Error reading from master")),
}
}

Expand Down

0 comments on commit dba9dd0

Please sign in to comment.