fix: gRPC balancer shutdown panic

The gRPC node discovery hack spawns a task that outlives the gRPC
balancer - once the balancer stops, the task should stop too (and not
panic sending on the closed channel).
pull/24376/head
Dom Dwyer 2023-01-10 20:28:47 +01:00
parent 5148e3343d
commit 6ef68513d9
No known key found for this signature in database
GPG Key ID: E4C40DBD9157879A
1 changed files with 16 additions and 6 deletions

View File

@ -42,12 +42,22 @@ where
tokio::spawn(async move {
loop {
for e in &endpoints {
tx.send(tower::discover::Change::Insert(
e.uri().to_owned(),
e.clone(),
))
.await
.expect("no grpc balance receiver");
// The gRPC balance listener will stop first during shutdown.
if tx
.send(tower::discover::Change::Insert(
e.uri().to_owned(),
e.clone(),
))
.await
.is_err()
{
// The gRPC balancer task has stopped - likely because
// the server has stopped.
//
// Do not leak this task, or panic trying to send on the
// closed channel.
return;
}
}
tokio::time::sleep(Duration::from_secs(5)).await;