pkg/tools/batcher: stop scheduler panicking when b.data is closed externally#3714
Merged
FGadvancer merged 2 commits intoJun 26, 2026
Merged
Conversation
…ernally
scheduler()'s defer unconditionally calls close(b.data). If the channel
was closed by the caller (or an upstream producer) instead of via the
normal Close()-sends-nil path, the receive on b.data returns ok == false,
scheduler returns, and the deferred close(b.data) then fires on an
already-closed channel:
panic: close of closed channel
reliably reproducible under the openimsdk#3653 steps (manually closing b.data
while Start() is running).
Track whether we observed the external-close via a local
`externallyClosed` flag set in the `ok == false` branch. The defer
only closes b.data when that flag is false, i.e. when the scheduler
exited through the nil-message or ticker paths and still owns the
channel. No behaviour change on the graceful Close() path.
Fixes openimsdk#3653
Contributor
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
Signed-off-by: SAY-5 <say.apm35@gmail.com>
Contributor
Author
|
Both failing checks look unrelated to this diff:
Happy to rebase or rerun if it'd help; the changes here are scoped to the WebSocket compress-buffer release path. |
aa2cade to
ade68df
Compare
withchao
approved these changes
Jun 26, 2026
FGadvancer
approved these changes
Jun 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3653.
scheduler()'s defer unconditionally callsclose(b.data). If the channel was closed by the caller (or an upstream producer) instead of via the normalClose()-sends-nil path, the receive onb.datareturnsok == false,schedulerreturns, and the deferredclose(b.data)then fires on an already-closed channel:reliably reproducible under the issue's steps (manually closing
b.datawhileStart()is running).This tracks whether we observed the external-close via a local
externallyClosedflag set in theok == falsebranch. The defer only closesb.datawhen that flag is false, i.e. when the scheduler exited through the nil-message or ticker paths and still owns the channel. No behaviour change on the gracefulClose()path.