A small HTTP handler saves a profile note by request key and returns a previously computed result on repeats. After a recent change, the behavior became unstable: sometimes the response contains incorrect data, and the incoming request body is not released when processing completes.
POST /notes.X-Request-Key header is required and is used as the idempotency key.{"user_id":"u1","text":"hello"}.id and status without creating a new note.409 Conflict.Body must be fully closed when processing finishes, even on validation errors or conflicts.POST /notes requests with the same X-Request-Key and the same body.text.Example request:
curl -i -X POST http://127.0.0.1:8080/notes \
-H 'Content-Type: application/json' \
-H 'X-Request-Key: k-1' \
--data '{"user_id":"u1","text":"hello"}'
201 Created.409 Conflict.go test ./...sync.Mutex/sync.RWMutexUse line comments to explain the problem, its impact, the fix and how to test it.