@@ -22,6 +22,7 @@ import (
2222 "go.opencensus.io/plugin/ochttp"
2323 "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
2424 "golang.org/x/net/http2"
25+ "golang.org/x/net/nettest"
2526 "golang.org/x/oauth2"
2627 "google.golang.org/api/googleapi/transport"
2728 "google.golang.org/api/internal"
@@ -266,6 +267,14 @@ func defaultBaseTransport(ctx context.Context, clientCertSource cert.Source, dia
266267 if trans == nil {
267268 trans = fallbackBaseTransport ()
268269 }
270+ trans .DialContext = func (ctx context.Context , network string , addr string ) (net.Conn , error ) {
271+ // Don't try IPv6 if it's not supported.
272+ // https://github.com/golang/go/issues/25321
273+ if ! nettest .SupportsIPv6 () {
274+ return baseDialContext (ctx , "tcp4" , addr )
275+ }
276+ return baseDialContext (ctx , network , addr )
277+ }
269278 trans .MaxIdleConnsPerHost = 100
270279
271280 if clientCertSource != nil {
@@ -275,7 +284,14 @@ func defaultBaseTransport(ctx context.Context, clientCertSource cert.Source, dia
275284 }
276285 if dialTLSContext != nil {
277286 // If DialTLSContext is set, TLSClientConfig wil be ignored
278- trans .DialTLSContext = dialTLSContext
287+ trans .DialTLSContext = func (ctx context.Context , network string , addr string ) (net.Conn , error ) {
288+ // Don't try IPv6 if it's not supported.
289+ // https://github.com/golang/go/issues/25321
290+ if ! nettest .SupportsIPv6 () {
291+ return dialTLSContext (ctx , "tcp4" , addr )
292+ }
293+ return dialTLSContext (ctx , network , addr )
294+ }
279295 }
280296
281297 configureHTTP2 (trans )
0 commit comments