headscale/hscontrol/mapper
Kristoffer Dalby 82c7efccf8 mapper/batcher: serialize per-node work to prevent out-of-order delivery
processBatchedChanges queued each pending change for a node as a
separate work item. Since multiple workers pull from the same channel,
two changes for the same node could be processed concurrently by
different workers. This caused two problems:

1. MapResponses delivered out of order — a later change could finish
   generating before an earlier one, so the client sees stale state.
2. updateSentPeers and computePeerDiff race against each other —
   updateSentPeers does Clear() + Store() which is not atomic relative
   to a concurrent Range() in computePeerDiff.

Bundle all pending changes for a node into a single work item so one
worker processes them sequentially. Add a per-node workMu that
serializes processing across consecutive batch ticks, preventing a
second worker from starting tick N+1 while tick N is still in progress.

Fixes #3140
2026-03-19 07:05:58 +01:00
..
batcher.go mapper/batcher: replace connected map with per-node disconnectedAt 2026-03-16 02:22:56 -07:00
batcher_bench_test.go mapper/batcher: replace connected map with per-node disconnectedAt 2026-03-16 02:22:56 -07:00
batcher_concurrency_test.go mapper/batcher: serialize per-node work to prevent out-of-order delivery 2026-03-19 07:05:58 +01:00
batcher_scale_bench_test.go mapper/batcher: replace connected map with per-node disconnectedAt 2026-03-16 02:22:56 -07:00
batcher_test.go mapper/batcher: remove disabled X-prefixed test functions 2026-03-14 02:52:28 -07:00
batcher_unit_test.go mapper/batcher: replace connected map with per-node disconnectedAt 2026-03-16 02:22:56 -07:00
builder.go all: fix golangci-lint issues (#3064) 2026-02-06 21:45:32 +01:00
builder_test.go all: fix golangci-lint issues (#3064) 2026-02-06 21:45:32 +01:00
mapper.go mapper: remove Batcher interface, rename to Batcher struct 2026-03-14 02:52:28 -07:00
mapper_test.go all: upgrade to Go 1.26rc2 and modernize codebase 2026-02-08 12:35:23 +01:00
node_conn.go mapper/batcher: replace connected map with per-node disconnectedAt 2026-03-16 02:22:56 -07:00
tail_test.go all: upgrade to Go 1.26rc2 and modernize codebase 2026-02-08 12:35:23 +01:00