Commit a2bb1cb
authored
fix(envd): fix data race in fan-out when subscriber is removed mid-iteration (#2643)
run() snapshots the m.channels slice header under RLock and iterates
after unlocking. remove() used append(channels[:i], channels[i+1:]...)
which shifts the shared backing array in-place, corrupting the
concurrent iteration — a subscriber can receive a value twice while
another misses it entirely.
Fix remove() to allocate a new backing array via slices.Concat so the
old slice that run() holds remains stable. This moves the allocation to
the cold path (subscriber disconnect) instead of the hot path (every
fan-out delivery).
Fixes: a67f983 ("fix(envd): fix fan-out deadlock when process subscriber disconnects (#2579)")1 parent ab62536 commit a2bb1cb
2 files changed
Lines changed: 4 additions & 2 deletions
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
128 | 129 | | |
129 | 130 | | |
130 | 131 | | |
131 | | - | |
| 132 | + | |
| 133 | + | |
132 | 134 | | |
133 | 135 | | |
134 | 136 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
0 commit comments