Can http.Request.Body be read after http.Client.Do returns?

61 views
Skip to first unread message

Gabriel Aszalos

unread,
Jul 22, 2019, 10:38:14 AM7/22/19
to golang-nuts
I have an odd race condition occasionally occurring in my code (hard to reproduce in non-production environment) but it might be hinting at the fact that `http.Client.Do` might be reading the `http.Request.Body` *after* it returns. Is this possible? I am re-using the same request body throughout requests. I've tried to dig into the net/http code but can't really figure it out. Looking simply at `http.Client.do`, it seems like the request body is always closed before each return (except the sentinel error from CheckRedirect, which we're not using).

Gabriel Aszalos

unread,
Jul 22, 2019, 10:40:02 AM7/22/19
to golang-nuts
In pseudo-code, something like this happens:

> req := http.NewRequest("POST", url, body)
> ...
> body.reset()
Reply all
Reply to author
Forward
0 new messages