Skip to content

fix(broker): delete leaked JetStream consumers on rule subject change - #40

Merged
danielmichaels merged 2 commits into
mainfrom
orphaned-consumers
May 7, 2026
Merged

fix(broker): delete leaked JetStream consumers on rule subject change#40
danielmichaels merged 2 commits into
mainfrom
orphaned-consumers

Conversation

@danielmichaels

@danielmichaels danielmichaels commented May 5, 2026

Copy link
Copy Markdown
Owner

Summary

Rule updates that change or remove a subject could leave JetStream durable consumers behind, and failed subscription startup could leave partial state behind. This PR makes those
updates atomic and ensures obsolete consumers are deleted when they are no longer referenced.

What changed

  • store both stream name and consumer name per subject so cleanup always targets the original durable consumer
  • apply rule updates as try-then-commit: start new NATS and HTTP subscriptions first, abort and roll back on failure, then commit rule state
  • remove NATS and outbound subscriptions only when the subject is no longer referenced by any remaining rule key
  • drain in-flight workers before deleting durable consumers to avoid Ack/Nak races and duplicate redelivery when the consumer is recreated
  • clean up orphaned consumers created by failed subscription or outbound registration attempts
  • treat missing consumers as an idempotent cleanup path and log manual cleanup only for real delete failures

Notes

  • this does not backfill cleanup for consumers leaked before this patch; existing orphans still need one-time manual cleanup

Fixes issue where consumers leak/persist when a rule no longer
references the consumer. This change will add new subscriptions and
remove old ones which no longer have any consumers.

Pre-existing ophans will need to be manually cleaned up.
`

Signed-off-by: Daniel Michaels <dan@danielms.site>
Signed-off-by: Daniel Michaels <dan@danielms.site>
@danielmichaels
danielmichaels merged commit cd7f08d into main May 7, 2026
2 checks passed
@danielmichaels
danielmichaels deleted the orphaned-consumers branch May 7, 2026 03:03
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.

1 participant