Skip to content

fix(bus): remove typed channels on Unsubscribe - #7011

Open
iliya-vidrush wants to merge 1 commit into
anomalyco:devfrom
iliya-vidrush:fix/bus-unsubscribe-typed-channels
Open

iliya-vidrush wants to merge 1 commit into
anomalyco:devfrom
iliya-vidrush:fix/bus-unsubscribe-typed-channels

Conversation

@iliya-vidrush

Copy link
Copy Markdown

Summary

  • Unsubscribe shortened bus.subscribers[t] through the range loop variable, so the result was never written back — channels from Subscribe were never removed and kept receiving events.
  • Store slices.DeleteFunc back into the map, which also replaces the backward index loops used to delete in place.
  • Behavior change: Publish now stops delivering to typed channels after Unsubscribe.

Validation

  • go build ./..., go vet ./pkg/bus/..., and go 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
Loading

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.
@AlperSakarya

Copy link
Copy Markdown

Thanks for the fix, @iliya-vidrush. The fix in this PR (removing typed channels on Unsubscribe) is in the community fork, sst-community/sst, through #7013, in sst-community/sst#27 (released in v4.18.0). The fork carries #7013's version of it, which also lets a typed subscription be passed to Unsubscribe.

The fork accepts issues and PRs, if you have other fixes you'd like carried.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants