Skip to content

Commit 4c903bc

Browse files
authored
node: remove potential deadlock on chan capacity of zero (#1116)
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. --> ## Overview There was a potential deadlock for a channel capacity of zero. This code removes that deadlock and adds a comment explaining the code more. Related to #1069 <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. --> ## Checklist <!-- Please complete the checklist to ensure that the PR is ready to be reviewed. IMPORTANT: PRs should be left in Draft until the below checklist is completed. --> - [ ] New and updated code has appropriate documentation - [ ] New and updated code has new and/or updated testing - [ ] Required CI checks are passing - [ ] Visual proof for any user facing features like CLI or documentation updates - [ ] Linked issues closed with keywords
1 parent dbb3bb7 commit 4c903bc

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

node/full_client.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -829,14 +829,16 @@ func (c *FullClient) eventsRoutine(sub cmtypes.Subscription, subscriber string,
829829
select {
830830
case msg := <-sub.Out():
831831
result := ctypes.ResultEvent{Query: q.String(), Data: msg.Data(), Events: msg.Events()}
832-
if cap(outc) == 0 {
833-
outc <- result
834-
} else {
835-
select {
836-
case outc <- result:
837-
default:
838-
c.Logger.Error("wanted to publish ResultEvent, but out channel is full", "result", result, "query", result.Query)
839-
}
832+
select {
833+
case outc <- result:
834+
default:
835+
// The default case can happen if the outc chan
836+
// is full or if it was initialized incorrectly
837+
// with a capacity of 0. Since this function has
838+
// no control over re-initializing the outc
839+
// chan, we do not block on a capacity of 0.
840+
full := cap(outc) != 0
841+
c.Logger.Error("wanted to publish ResultEvent, but out channel is full:", full, "result:", result, "query:", result.Query)
840842
}
841843
case <-sub.Cancelled():
842844
if sub.Err() == cmpubsub.ErrUnsubscribed {

0 commit comments

Comments
 (0)