Skip to content

fix: remove erroneous break in Stats() pubCounts loop#1526

Closed
goingforstudying-ctrl wants to merge 2 commits into
nsqio:masterfrom
goingforstudying-ctrl:fix/stats-pubcounts-break
Closed

fix: remove erroneous break in Stats() pubCounts loop#1526
goingforstudying-ctrl wants to merge 2 commits into
nsqio:masterfrom
goingforstudying-ctrl:fix/stats-pubcounts-break

Conversation

@goingforstudying-ctrl

@goingforstudying-ctrl goingforstudying-ctrl commented May 23, 2026

Copy link
Copy Markdown

Closing this PR as it's no longer needed.

The break statement on line 325 caused the Stats() method to only
record one topic per client when multiple topics were published to.
This meant that when a client published to multiple topics, only
the first topic's publish count would appear in statistics.

Removing the break allows all topics to be collected correctly.

This is a clear bug with user impact - anyone monitoring multi-topic
client publish counts would see incomplete data.
@goingforstudying-ctrl

Copy link
Copy Markdown
Author

Hi @mreiferson @ploxiln — this is a clear bugfix for multi-topic publish stats. Any chance someone could take a quick look? Happy to rebase if needed.

@goingforstudying-ctrl

Copy link
Copy Markdown
Author

CI is green, no conflicts. One-line bugfix removing an erroneous break in the Stats() loop. Ready for review.

@ploxiln

ploxiln commented May 25, 2026

Copy link
Copy Markdown
Member

I see, this matters when topic is blank, meaning all topics

(would be nice to have a test for this bit of behavior :)

@goingforstudying-ctrl

Copy link
Copy Markdown
Author

Good point — I'll add a test case for the multi-topic (blank topic) path and push an update shortly.

Adds a test verifying that Stats() returns pubCounts for all topics
when called with a blank topic name, and only the matching topic
when called with a specific topic name.

Addresses review feedback from ploxiln.
@goingforstudying-ctrl

Copy link
Copy Markdown
Author

@ploxiln Added in — covers the blank-topic (all topics) and specific-topic filtering paths. Pushed. Let me know if you'd like anything else adjusted.

@goingforstudying-ctrl

Copy link
Copy Markdown
Author

@ploxiln Added TestClientStatsPubCounts in stats_test.go — it sets up an nsqd instance, publishes to two topics over the same producer connection, and asserts that both topics show up in the producer client stats with the correct counts. Confirmed it fails with the break in place and passes without it.

@ploxiln

ploxiln commented May 26, 2026

Copy link
Copy Markdown
Member

I have awkwardly just realized that there are two older PRs with the same fix:

... what might justify this one is addressing the comment in #1497 :)

@goingforstudying-ctrl

Copy link
Copy Markdown
Author

@ploxiln thanks for catching that — I wasn't aware of #1525 and #1497. You're right that the test addition is the main differentiator here. The break causes only the first topic's pub count to be recorded when querying all topics, which is a real bug for anyone running multi-topic workloads. Happy to close this in favor of one of the older PRs if a maintainer prefers, but since the test is already written and pushed, I'll leave it open in case it's useful. Let me know if you'd like me to rebase or adjust anything.

@goingforstudying-ctrl

Copy link
Copy Markdown
Author

Thanks for the review and approval, @ploxiln! Appreciate you catching the overlap with #1525 and #1497 too — the test coverage for the blank-topic path should hopefully make this one useful regardless. Let me know if there's anything else you'd like adjusted.

@goingforstudying-ctrl goingforstudying-ctrl deleted the fix/stats-pubcounts-break branch May 30, 2026 18:08
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