Repository navigation
fix(bus): remove typed channels on Unsubscribe - #7011
Open
iliya-vidrush wants to merge 1 commit into
Open
iliya-vidrush wants to merge 1 commit into
iliya-vidrush wants to merge 1 commit into
Conversation
Unsubscribe ranged over bus.subscribers and shortened the slice through the loop variable, so the shortened result was never stored back in the map. Channels registered via Subscribe were therefore never removed, and Publish kept sending events to them after unsubscribing. Assign slices.DeleteFunc back into bus.subscribers[t], which also replaces the backward index loops both branches used to delete in place.
|
Thanks for the fix, @iliya-vidrush. The fix in this PR (removing typed channels on The fork accepts issues and PRs, if you have other fixes you'd like carried. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Unsubscribeshortenedbus.subscribers[t]through the range loop variable, so the result was never written back — channels fromSubscribewere never removed and kept receiving events.slices.DeleteFuncback into the map, which also replaces the backward index loops used to delete in place.Publishnow stops delivering to typed channels afterUnsubscribe.Validation
go build ./...,go vet ./pkg/bus/..., andgo test ./pkg/bus/...pass.Flow
%%{init: {'themeVariables': {'fontSize': '12px'}}}%% flowchart TB classDef added fill:#dcfce7,stroke:#16a34a,color:#166534 classDef changed fill:#fef3c7,stroke:#d97706,color:#92400e classDef removed fill:#fee2e2,stroke:#dc2626,color:#991b1b unsub["bus.Unsubscribe(ch)"] --> all["slices.DeleteFunc(bus.all, isTarget)"] unsub ==>|"result stored in the map"| subs["bus.subscribers[t] = slices.DeleteFunc(...)"] unsub -.->|"wrote to the loop copy"| loopvar["channels = append(channels[:i], ...)"] subs --> publish["bus.Publish(event)"] all --> publish class subs added class all changed class loopvar removed