Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
x/net/http2: data race in request body buffer sharing #14960
I suspect I introduced a data race in https://go-review.googlesource.com/20542 when I introduced the reuse of the 64k request body buffers.
From a grpc-go travis failure (grpc/grpc-go#604):
The Read and Write calls are both protected by a mutex, but at this point it's a different mutex I suspect, with each caller having a different
We can't return the buffer when the stream closes, as a caller might still be using it in their ServeHTTP goroutine. Instead, we can have the ServeHTTP goroutine's exit itself return it, after first acquiring the lock and niling it out, in case the ServeHTTP goroutine retains the request.body somehow.
Git rev e7da8ed (CL 20542) introduced an optimization to reuse the 64k request body buffers across multiple requests. But ServeHTTP handlers could retain them too long and cause races. Temporarily revert the main part of that CL until a proper fix is in. Updates golang/go#14960 Updates grpc/grpc-go#604 Change-Id: I28450e797a1d3122868214700b6ef345a0a1a47c Reviewed-on: https://go-review.googlesource.com/21160 Reviewed-by: Brad Fitzpatrick <email@example.com>
name old time/op new time/op delta ServerPosts-4 192µs ± 1% 164µs ± 1% -14.16% (p=0.000 n=17+19) name old alloc/op new alloc/op delta ServerPosts-4 69.8kB ± 0% 2.8kB ± 0% -95.95% (p=0.000 n=18+18) name old allocs/op new allocs/op delta ServerPosts-4 42.0 ± 0% 40.0 ± 0% -4.76% (p=0.000 n=20+20) This is a redo of git rev e7da8ed (golang.org/cl/20542) which had a race and was later reverted in golang.org/cl/21160. Updates golang/go#14960 Updates grpc/grpc-go#604 Change-Id: Ie216e45730dce4fc0c58f295bcbc669973145599 Reviewed-on: https://go-review.googlesource.com/31447 Run-TryBot: Brad Fitzpatrick <firstname.lastname@example.org> TryBot-Result: Gobot Gobot <email@example.com> Reviewed-by: Ian Lance Taylor <firstname.lastname@example.org>