Repository navigation
fix(fabric/delivery): stop leaking the receiver goroutine and its stream on shutdown - #1894
Conversation
|
Hey @mbrandenburger 👋 thanks for the PR! This comment updates automatically as you push changes -- think of it as your PR's live scoreboard! 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:
You'll need to sign your commits with GPG (e.g. ✅ 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! |
…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>
06a7932 to
2f16822
Compare
|
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. |
What and why
runReceiver's outerselecthad acase <-d.stopthat returned without callingdfCancel(), while the nesteddefaultbranch's owncase <-d.stopdid call it correctly. Sinceselectonly falls through todefaultwhen no other case is ready, the outer case won every timed.stopclosed, so the canceling branch never ran and everyStop()left the current Deliver stream's context open.handleBlockResponsesent to the boundedchchannel unconditionally. OncereadBlocksstopped draining it, for example right afterStop, that send blocked forever, pinning therunReceivergoroutine and its stream for the life of the process.This flattens
runReceiver'sselectso thed.stopcase always cancels the stream before returning, and guardshandleBlockResponse's send with aselectagainstd.stopso it returns instead of blocking once the service is stopping.Also in this diff:
Service/Delivery's unusedmetrics.Providerparameter and the two DI call sites that passed it (platform/fabric/sdk/dig/generic/providers.go,platform/fabricx/sdk/dig/providers.go).DeliverFiltered/DeliverStreaminterfaces indeliverclient.gointo a type alias.Scan/ScanFromBlock's duplicated body into a sharedscanTransactionshelper, 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/... -racemake checksNotes for reviewers
The two leak fixes are the core of the diff (
delivery.go); themetrics.Providerremoval, interface merge, andscanTransactionsextraction are incidental cleanups noticed while reading through the same file and its callers.