Skip to content

fix(fabric/delivery): stop leaking the receiver goroutine and its stream on shutdown - #1894

Merged
SaidAltury-ibm merged 1 commit into
hyperledger-labs:mainfrom
mbrandenburger:fix/delivery-receiver-cleanup
Sep 27, 2026
Merged

SaidAltury-ibm merged 1 commit into
hyperledger-labs:mainfrom
mbrandenburger:fix/delivery-receiver-cleanup

Conversation

@mbrandenburger

Copy link
Copy Markdown
Member

What and why

runReceiver's outer select had a case <-d.stop that returned without calling dfCancel(), while the nested default branch's own case <-d.stop did call it correctly. Since select only falls through to default when no other case is ready, the outer case won every time d.stop closed, so the canceling branch never ran and every Stop() left the current Deliver stream's context open.

handleBlockResponse sent to the bounded ch channel unconditionally. Once readBlocks stopped draining it, for example right after Stop, that send blocked forever, pinning the runReceiver goroutine and its stream for the life of the process.

This flattens runReceiver's select so the d.stop case always cancels the stream before returning, and guards handleBlockResponse's send with a select against d.stop so it returns instead of blocking once the service is stopping.

Also in this diff:

  • Dropped Service/Delivery's unused metrics.Provider parameter and the two DI call sites that passed it (platform/fabric/sdk/dig/generic/providers.go, platform/fabricx/sdk/dig/providers.go).
  • Merged the identical DeliverFiltered/DeliverStream interfaces in deliverclient.go into a type alias.
  • Extracted Scan/ScanFromBlock's duplicated body into a shared scanTransactions helper, dropping two dead commented-out lines along the way.

Fixes #1893

How it was verified

  • go build ./..., go vet ./...
  • go test ./platform/fabric/core/generic/delivery/... -race
  • make checks

Notes for reviewers

The two leak fixes are the core of the diff (delivery.go); the metrics.Provider removal, interface merge, and scanTransactions extraction are incidental cleanups noticed while reading through the same file and its callers.

@mbrandenburger mbrandenburger added this to the 26Q3 milestone Sep 25, 2026
@mbrandenburger mbrandenburger self-assigned this Sep 25, 2026
@mbrandenburger mbrandenburger added the bug Something isn't working label Sep 25, 2026
@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Hey @mbrandenburger 👋 thanks for the PR!
I'm your friendly PR Helper Bot 🤖 and I'll be riding shotgun on this one, keeping track of your PR's status to help you get it approved and merged.

This comment updates automatically as you push changes -- think of it as your PR's live scoreboard!
Here's the latest:


PR Checks

✅ DCO Sign-off -- All commits have valid sign-offs. Nice work!


❌ GPG Signature -- Heads up! The following commits don't have a verified GPG signature:

  • 2f16822 fix(fabric/delivery): stop leaking the receiver goroutine and its stream on shutdown

You'll need to sign your commits with GPG (e.g. git commit -S). See the Signing Guide for a step-by-step walkthrough.


✅ Merge Conflicts -- No merge conflicts detected. Smooth sailing!


✅ Issue Link -- Linked to #1893 (assigned to you).


⏳ All checks must pass before this PR can be reviewed. You've got this!

@github-actions github-actions Bot added the status: needs revision The pull request requires changes from the author before it can be reviewed or merged label Sep 25, 2026
@mbrandenburger mbrandenburger added status: needs review The pull request is ready for maintainer review and removed status: needs revision The pull request requires changes from the author before it can be reviewed or merged labels Sep 25, 2026
…eam on shutdown

runReceiver's stop case was nested inside a select's default branch, so
whenever d.stop and the default case were both ready, select could pick
default and skip closing the current Deliver stream's context, leaking it.
handleBlockResponse also sent to the bounded result channel unconditionally,
so once the reader stopped draining it, that send could block forever and
leak the goroutine along with the stream it never releases. Flatten the
select and race the channel send against d.stop so both paths always tear
down cleanly.

Also drop the delivery service's unused metrics.Provider parameter, merge
the identical DeliverFiltered/DeliverStream interfaces into an alias, and
extract the duplicated Scan/ScanFromBlock body into one helper.

Signed-off-by: Marcus Brandenburger <bur@zurich.ibm.com>
@SaidAltury-ibm
SaidAltury-ibm force-pushed the fix/delivery-receiver-cleanup branch from 06a7932 to 2f16822 Compare September 27, 2026 09:18
@github-actions github-actions Bot added status: needs revision The pull request requires changes from the author before it can be reviewed or merged and removed status: needs review The pull request is ready for maintainer review labels Sep 27, 2026
@mergify

mergify Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@SaidAltury-ibm
SaidAltury-ibm merged commit 9509f8a into hyperledger-labs:main Sep 27, 2026
45 checks passed
@mbrandenburger
mbrandenburger deleted the fix/delivery-receiver-cleanup branch September 28, 2026 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working status: needs revision The pull request requires changes from the author before it can be reviewed or merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fabric/delivery: runReceiver leaks its goroutine and gRPC stream on Stop

2 participants