Skip to content

[CRE][Limits] Handle limit flip to zero and back correctly#1762

Merged
bolekk merged 1 commit intomainfrom
CRE-1646-zero-queue-bug
Jan 9, 2026
Merged

[CRE][Limits] Handle limit flip to zero and back correctly#1762
bolekk merged 1 commit intomainfrom
CRE-1646-zero-queue-bug

Conversation

@bolekk
Copy link
Copy Markdown
Contributor

@bolekk bolekk commented Jan 8, 2026

No description provided.

@bolekk bolekk requested a review from a team as a code owner January 8, 2026 23:44
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 8, 2026

👋 bolekk, thanks for creating this pull request!

To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team.

Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks!

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 8, 2026

✅ API Diff Results - No breaking changes


📄 View full apidiff report

@bolekk bolekk enabled auto-merge January 9, 2026 15:17
}

func (l *resourcePoolLimiter[N]) setOnLimitUpdate(fn func(ctx context.Context)) {
l.updater.onLimitUpdate = fn
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

does this need a write lock?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, it's internal and only used by constructors.

ctx := t.Context()

// Consume the single available resource to force the next waiter to enqueue.
freeFirst, err := limiter.Wait(ctx, 1)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is there still a corner case here?:

we set the limit to zero
the node restarts
this wait blocks on ctx, which in core node is forever atm
we set the limit to 1
whatever else was waiting starts
the original is stuck forever

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Waiters don't only block on context, they block on both their context AND the queue channel. In this case it will get its channel unblocked when the limit is set to 1.

I don't believe there's a problem but if you disagree can you try proving it in a unit test (tell an LLM to do it)?

Copy link
Copy Markdown
Contributor

@krehermann krehermann Jan 9, 2026

Choose a reason for hiding this comment

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

as long as the Wait is happening in a different go routine than the set we are good; i assume that must be true in the core node. the test as written
~

Wait(ctx, foo)
Set(foo)

will block until ctx expiration in wait and never get to Set, but iiuc, that is simply test artifact

@bolekk bolekk added this pull request to the merge queue Jan 9, 2026
Merged via the queue into main with commit 8bde3ee Jan 9, 2026
36 checks passed
@bolekk bolekk deleted the CRE-1646-zero-queue-bug branch January 9, 2026 16:09
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.

3 participants