Question about httptrace synchronization

77 views
Skip to first unread message

Eli Lindsey

unread,
Oct 26, 2023, 3:42:27 PM10/26/23
to golang-nuts
Example code (note that it won’t actually execute in the playground since it’s making network calls):

My assumption was that this code is a potential data race and requires additional synchronization on t. net/http/httptrace in particular says: "Functions may be called concurrently from different goroutines and some may be called after the request has completed or failed.”

However, I see code sans synchronization frequently in the wild, httpstat being one example (https://github.com/davecheney/httpstat/blob/master/main.go#L221).

Is there some additional synchronization guarantee provided by eg. client.Do() that I’m missing and that makes this safe, or is the fact that it doesn’t trip a race happenstance? 

-eli

Reply all
Reply to author
Forward
0 new messages