Skip to content

fix(msggateway): avoid reusing Clients backing array - #3768

Open
buvidk1234 wants to merge 1 commit into
openimsdk:mainfrom
buvidk1234:fix/user-map-slice-race
Open

fix(msggateway): avoid reusing Clients backing array#3768
buvidk1234 wants to merge 1 commit into
openimsdk:mainfrom
buvidk1234:fix/user-map-slice-race

Conversation

@buvidk1234

Copy link
Copy Markdown
Contributor

🅰 Please add the issue ID after "Fixes #"

Fixes #

Summary

Fix UserMap.DeleteClients to avoid overwriting client slices that were previously returned by GetAll.

Problem

DeleteClients used result.Clients[:0] before rebuilding the remaining client list. This preserves the original capacity, so subsequent append calls reuse and overwrite the same backing array.

Callers such as RPC push or multi-login checks may already hold a slice returned by GetAll and iterate it after UserMap releases its lock. When DeleteClients runs concurrently, those callers can observe mutated slice contents, for example [A, B, C] becoming [B, C, C].

Changes

Use result.Clients[:0:0] so the rebuilt client list gets a new backing array while keeping the existing filtering logic unchanged.

@pull-request-size pull-request-size Bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant