Skip to content

fix(pubsub): Publisher byte threshold off by one error#4651

Merged
PhongChuong merged 2 commits intogoogleapis:mainfrom
PhongChuong:threshold
Feb 13, 2026
Merged

fix(pubsub): Publisher byte threshold off by one error#4651
PhongChuong merged 2 commits intogoogleapis:mainfrom
PhongChuong:threshold

Conversation

@PhongChuong
Copy link
Copy Markdown
Collaborator

This PR fix the issue where the Publisher configured byte threshold is not respected. In the bug, the Publisher will add the next message to the pending batch until the batch size is greater then the byte threshold. The correct behavior is to batch the messages such that each batch size is less or equal to the configured byte threshold.

In the fix, we add the next message to the batch only if the batch will stay within the configured byte threshold. This is done lazily and the pending batch is not Send until we know that the next message will not fit.

@product-auto-label product-auto-label bot added the api: pubsub Issues related to the Pub/Sub API. label Feb 10, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.03%. Comparing base (759f195) to head (38863e2).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4651      +/-   ##
==========================================
+ Coverage   95.01%   95.03%   +0.01%     
==========================================
  Files         196      196              
  Lines        7530     7551      +21     
==========================================
+ Hits         7155     7176      +21     
  Misses        375      375              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@PhongChuong PhongChuong marked this pull request as ready for review February 10, 2026 22:00
@PhongChuong PhongChuong requested a review from a team as a code owner February 10, 2026 22:00

let mut publish_rxs = VecDeque::new();
publish_random_data!(publish_rxs, actor_tx, 1);
// We flush here otherwise the last message will await forever since it never exceed the byte threshold.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

aside: I think actually with start_paused = true, the testing framework will fire the timer if its the only thing that can happen, so this might not be necessary.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The flush is needed here because the timer is in the Dispatcher.

@PhongChuong
Copy link
Copy Markdown
Collaborator Author

@suzmue , thanks for the review. PTAL.

@PhongChuong PhongChuong merged commit 35df47c into googleapis:main Feb 13, 2026
34 checks passed
@PhongChuong PhongChuong deleted the threshold branch February 19, 2026 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: pubsub Issues related to the Pub/Sub API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants