danielgtaylor/huma

Data race when consuming input RawBody

Opened this issue · 1 comments

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

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.