Skip to content

pkg/tools/batcher: stop scheduler panicking when b.data is closed externally#3714

Merged
FGadvancer merged 2 commits into
openimsdk:mainfrom
SAY-5:fix/batcher-scheduler-double-close-3653
Jun 26, 2026
Merged

pkg/tools/batcher: stop scheduler panicking when b.data is closed externally#3714
FGadvancer merged 2 commits into
openimsdk:mainfrom
SAY-5:fix/batcher-scheduler-double-close-3653

Conversation

@SAY-5

@SAY-5 SAY-5 commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #3653.

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 issue's steps (manually closing b.data while Start() is running).

This tracks 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.

…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
@pull-request-size pull-request-size Bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Apr 20, 2026
@github-actions

github-actions Bot commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

🤖 All Contributors have signed the CLA.
The signed information is recorded here
Posted by the CLA Assistant Lite bot.

@SAY-5

SAY-5 commented Apr 30, 2026

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

Signed-off-by: SAY-5 <say.apm35@gmail.com>
@SAY-5

SAY-5 commented May 2, 2026

Copy link
Copy Markdown
Contributor Author

Both failing checks look unrelated to this diff:

  • Benchmark Test: check num:40, conversation num un correct, userID=test_v3_u18, ConversationNum=5, correct num=7, this is the integration counter checker in openim-sdk-core/integration_test failing on a state-setup race, not anything in pkg/msggateway.
  • Build and Test Dockerfile (1.22): same overall run failure, no diff-related compile errors.

Happy to rebase or rerun if it'd help; the changes here are scoped to the WebSocket compress-buffer release path.

@SAY-5 SAY-5 force-pushed the fix/batcher-scheduler-double-close-3653 branch from aa2cade to ade68df Compare May 31, 2026 02:41
@FGadvancer FGadvancer added this pull request to the merge queue Jun 26, 2026
Merged via the queue into openimsdk:main with commit b3a7342 Jun 26, 2026
6 of 10 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Batcher scheduler may panic on double close of data channel

3 participants