-
Notifications
You must be signed in to change notification settings - Fork 679
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't use sync.Pool for json.NewEncoder target buffers (#421)
* Don't release buf to sync.Pool to early The slice returned by `noescapeJSONMarshal` continues to be accessed even after `pool.Put` was called on the buffer. This might lead to incorrect data being sent in request body if the buffer is acquired and re-written by a concurrently running goroutine. So make sure we release the buffer once the request completes. * Release request body buf back to sync.Pool only after body is closed net/http.RoundTripper may access request body in a separate goroutine, so we need to wait release the buf back to sync.Pool only after the body is closed. From the docs: // RoundTrip must always close the body, including on errors, // but depending on the implementation may do so in a separate // goroutine even after RoundTrip returns. This means that // callers wanting to reuse the body for subsequent requests // must arrange to wait for the Close call before doing so.
- Loading branch information
1 parent
d717652
commit c1fa358
Showing
4 changed files
with
50 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters