@@ -22,6 +22,7 @@ import (
22
22
"go.opencensus.io/plugin/ochttp"
23
23
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
24
24
"golang.org/x/net/http2"
25
+ "golang.org/x/net/nettest"
25
26
"golang.org/x/oauth2"
26
27
"google.golang.org/api/googleapi/transport"
27
28
"google.golang.org/api/internal"
@@ -266,6 +267,14 @@ func defaultBaseTransport(ctx context.Context, clientCertSource cert.Source, dia
266
267
if trans == nil {
267
268
trans = fallbackBaseTransport ()
268
269
}
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
+ }
269
278
trans .MaxIdleConnsPerHost = 100
270
279
271
280
if clientCertSource != nil {
@@ -275,7 +284,14 @@ func defaultBaseTransport(ctx context.Context, clientCertSource cert.Source, dia
275
284
}
276
285
if dialTLSContext != nil {
277
286
// 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
+ }
279
295
}
280
296
281
297
configureHTTP2 (trans )
0 commit comments