Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http: docs for Dial and DialContext should indicate concurrency properties #25019

Closed
jsha opened this issue Apr 23, 2018 · 2 comments
Closed

net/http: docs for Dial and DialContext should indicate concurrency properties #25019

jsha opened this issue Apr 23, 2018 · 2 comments

Comments

@jsha
Copy link

@jsha jsha commented Apr 23, 2018

In Go 1.10.1, a user of the net/http package can specify a custom RoundTripper. That RoundTripper can define a custom Dial and/or DialContext. When running Client.Do, the Dial or DialContext function is run on a separate goroutine. If the function has side effects (for instance, recording its results in a shared slice), this can cause race conditions. For a real-world example, see letsencrypt/boulder#3109.

I think the documentation should be updated to mention that Dial and DialContext may be run concurrently with the function calling Client.Do. Here's the current documenation:

https://godoc.org/net/http#Transport

// DialContext specifies the dial function for creating unencrypted TCP connections.
// If DialContext is nil (and the deprecated Dial below is also nil),
// then the transport dials using package net.
DialContext func(ctx context.Context, network, addr string) (net.Conn, error)

// Dial specifies the dial function for creating unencrypted TCP connections.
//
// Deprecated: Use DialContext instead, which allows the transport
// to cancel dials as soon as they are no longer needed.
// If both are set, DialContext takes priority.
Dial func(network, addr string) (net.Conn, error)

Thanks!

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Apr 23, 2018

@ianlancetaylor ianlancetaylor added this to the Go1.11 milestone Apr 23, 2018
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Jun 5, 2018

Change https://golang.org/cl/116375 mentions this issue: net/http: document Transport.Dial concurrency

@bradfitz bradfitz self-assigned this Jun 5, 2018
@gopherbot gopherbot closed this in db49f76 Jun 5, 2018
@golang golang locked and limited conversation to collaborators Jun 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.