From 778be06de8fa3615758ad15d23d27ac673809867 Mon Sep 17 00:00:00 2001 From: "M. J. Fromberger" Date: Tue, 23 Nov 2021 12:26:22 -0800 Subject: [PATCH] pubsub: Report a non-nil error when shutting down. (#7310) If a subscriber arrives while the pubsub service is shutting down, the existing code will return a nil subscription without error. With unlucky timing, this may lead to a nil indirection panic in the RPC service. To avoid that problem, make sure that when a subscription fails for this reason, we report a non-nil error so that the client will detect it and give up gracefully. --- CHANGELOG_PENDING.md | 6 ++++-- libs/pubsub/pubsub.go | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 58dbd8b69..241b0bfa5 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -12,13 +12,13 @@ Special thanks to external contributors on this release: - CLI/RPC/Config - - [config] \#7276 rpc: Add experimental config params to allow for subscription buffer size control (@thanethomson). + - [config] [\#7276](https://github.com/tendermint/tendermint/pull/7276) rpc: Add experimental config params to allow for subscription buffer size control (@thanethomson). - Apps - P2P Protocol - - [p2p] \#7265 Peer manager reduces peer score for each failed dial attempts for peers that have not successfully dialed. (@tychoish) + - [p2p] [\#7265](https://github.com/tendermint/tendermint/pull/7265) Peer manager reduces peer score for each failed dial attempts for peers that have not successfully dialed. (@tychoish) - Go API @@ -29,3 +29,5 @@ Special thanks to external contributors on this release: ### IMPROVEMENTS ### BUG FIXES + +- [\#7310](https://github.com/tendermint/tendermint/issues/7310) pubsub: Report a non-nil error when shutting down (fixes #7306). diff --git a/libs/pubsub/pubsub.go b/libs/pubsub/pubsub.go index 68d1ec941..6ecf5acbd 100644 --- a/libs/pubsub/pubsub.go +++ b/libs/pubsub/pubsub.go @@ -219,7 +219,7 @@ func (s *Server) subscribe(ctx context.Context, clientID string, query Query, ou case <-ctx.Done(): return nil, ctx.Err() case <-s.Quit(): - return nil, nil + return nil, errors.New("service is shutting down") } }