danielgtaylor / huma

Huma REST/HTTP API Framework for Golang with OpenAPI 3.1
https://huma.rocks/
MIT License
1.95k stars 144 forks source link

Data race when consuming input RawBody #467

Closed jonandernovella closed 1 month ago

jonandernovella commented 4 months ago

I think we have spotted a data race when consuming the raw body of the input across multiple go routines.

Here a minimal environment where we manage to reproduce this: https://github.com/jonandernovella/huma-par-body/tree/main

One may detect the data race running: go test -v -race

danielgtaylor commented 4 months ago

Thanks for reporting this! My initial suspicion is around re-use of the underlying data buffers via sync.Pool here, which we may need to defer putting back into the pool until after the handler has run: https://github.com/danielgtaylor/huma/blob/main/huma.go#L1289-L1290. I will do some testing on my side to confirm and fix ASAP.