A small HTTP handler saves an event card and supports retries by Idempotency-Key. After a recent change, the behavior became unstable: for some requests the response is returned before the write completes, and a retry may diverge from the already saved result.
POST /events handler accepts JSON {"id":"...","title":"..."}.Idempotency-Key header is required; an empty key is a 400 error.201 with body {"status":"created"}.:8080.POST /events requests with the same Idempotency-Key but different title values.Example request:
curl -i -X POST http://localhost:8080/events \
-H 'Content-Type: application/json' \
-H 'Idempotency-Key: abc-123' \
-d '{"id":"e1","title":"Launch"}'
go test ./... and manual launch with go run .Store is accessible from multiple goroutines; all reads and writes to Store must be protected by a single mutex; there are no background goroutines after the responseUse line comments to explain the problem, its impact, the fix and how to test it.