Skip to content

Fixup consumer ref in backpressure update#6482

Merged
jasnell merged 1 commit intomainfrom
jasnell/fixup-consumer-ref
Apr 2, 2026
Merged

Fixup consumer ref in backpressure update#6482
jasnell merged 1 commit intomainfrom
jasnell/fixup-consumer-ref

Conversation

@jasnell
Copy link
Copy Markdown
Collaborator

@jasnell jasnell commented Apr 2, 2026

No description provided.

@jasnell jasnell requested review from a team as code owners April 2, 2026 00:04
Copy link
Copy Markdown
Contributor

@ask-bonk ask-bonk bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This review was generated by an AI code review assistant.

Nit: stale comment describing the old approach.

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk bot commented Apr 2, 2026

The review was posted successfully. Let me summarize my analysis:

I'm Bonk, and I've done a quick review of your PR.

This PR replaces a raw kj::Maybe<QueueImpl&> capture in UpdateBackpressureScope with a kj::Rc<WeakRef<ConsumerImpl>>, using runIfAlive to safely access the queue through the consumer at destruction time rather than holding a potentially-dangling queue reference.

The fix is sound — the old code captured the queue reference directly, but if the consumer was destroyed during the scope (e.g., via onConsumerErrorowner.doError()), the consumer's destructor calls q.removeConsumer(*this) which calls maybeUpdateBackpressure(), and then the scope destructor would also try to call maybeUpdateBackpressure() through the same queue ref. Worse, if the queue itself was destroyed in the interim, the reference would dangle. The new approach via WeakRef::runIfAlive is strictly safer.

One minor finding posted as a review comment: the comment above the struct still describes the old "captures the queue" approach and should be updated to reflect that it now captures a weak ref to the consumer.

github run

@jasnell jasnell force-pushed the jasnell/fixup-consumer-ref branch from 7b5eeea to 4fd20f1 Compare April 2, 2026 00:07
@jasnell jasnell enabled auto-merge April 2, 2026 00:59
@jasnell jasnell merged commit 55fbbf3 into main Apr 2, 2026
35 of 39 checks passed
@jasnell jasnell deleted the jasnell/fixup-consumer-ref branch April 2, 2026 01:42
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