fix http server race
Created by: ChrisSchinnerl
This PR fixes the random race condition when we call WriteJSON
.
It seems like the std lib flushes the underlying buffer in FinishRequest
, but before calling FinishRequest
it cancels the context. This means, that r.Context().Done()
will always trigger before done
in our select
and might cause a situation where FinishRequest
is called at the same time as ServeHTTP
. Both of those functions use the same buffer.