From f8802684d430c13ee8eeff3ebb5c59821d48666b Mon Sep 17 00:00:00 2001 From: Matthew Sevey Date: Mon, 31 Jul 2023 10:04:07 -0400 Subject: [PATCH] node: remove potential deadlock on chan capacity of zero --- node/full_client.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/node/full_client.go b/node/full_client.go index 0dd8f2ac2d..4dac9f5a1a 100644 --- a/node/full_client.go +++ b/node/full_client.go @@ -829,14 +829,16 @@ func (c *FullClient) eventsRoutine(sub cmtypes.Subscription, subscriber string, select { case msg := <-sub.Out(): result := ctypes.ResultEvent{Query: q.String(), Data: msg.Data(), Events: msg.Events()} - if cap(outc) == 0 { - outc <- result - } else { - select { - case outc <- result: - default: - c.Logger.Error("wanted to publish ResultEvent, but out channel is full", "result", result, "query", result.Query) - } + select { + case outc <- result: + default: + // The default case can happen if the outc chan + // is full or if it was initialized incorrectly + // with a capacity of 0. Since this function has + // no control over re-initializing the outc + // chan, we do not block on a capacity of 0. + full := cap(outc) != 0 + c.Logger.Error("wanted to publish ResultEvent, but out channel is full:", full, "result:", result, "query:", result.Query) } case <-sub.Cancelled(): if sub.Err() == cmpubsub.ErrUnsubscribed {