1

According to http.Client and http.Transport documentation in Go's built-in net/http package:

// The Client's Transport typically has internal state (cached TCP
// connections), so Clients should be reused instead of created as
// needed. Clients are safe for concurrent use by multiple goroutines.

So I just wonder: is it safe for concurrent modification too or not? since I wanna perform 20K http.Request with single http.Client struct and different values concurrently, not consecutively.

4
  • 6
    It is not safe for the application to modify client or transport fields concurrently. It is safe to execute requests on a client and transport concurrently. Commented Jul 23, 2023 at 23:12
  • 4
    No values are safe for concurrent modification. Commented Jul 24, 2023 at 0:16
  • 4
    It helps to consider there's no magic: the types in question are safe for concurrent use which means reading their fields and calling their methods which implement synchronisation where needed. Writing fields of values of the types in question while these fields are read concurrently would create plain old boring data races. Hence the answer to your question is no. Commented Jul 24, 2023 at 0:29
  • As stated in the documentation, http.Client is safe for concurrent use by multiple goroutines, which means you can use a single http.Client instance to perform multiple HTTP requests concurrently from different goroutines Commented Jul 24, 2023 at 4:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.