fix(push): Broadcast shares one payload slice across dispatch goroutines — data race #109
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Cloonar/coding-lab#109
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Found while landing PR #103 (out of scope for that change;
internal/pushis untouched by it — this is pre-existing #98 code).Symptom
go test -race ./internal/push/fails onmain.Repro:
Root cause
Sender.Broadcastmarshals the payload once and hands the same[]byteto every dispatch goroutine (internal/push/sender.go~L103-113). webpush-go v1.4.0 then doesbytes.NewBuffer(message)and appends padding into the slice's spare capacity (webpush.go~L179-186). Sincejson.Marshalroutinely returns a slice withcap > len, N subscriptions means N goroutines writing into the same backing array concurrently.Fix
Give each dispatch its own copy of the bytes, e.g.:
One line; a
-racetest over a multi-subscription broadcast should regress it.