Skip to content

Commit

Permalink
compute/metadata: workaround for App Engine SDK's broken build tags i…
Browse files Browse the repository at this point in the history
…n dev

See comments from Péter Szilágyi and David Symonds at
https://code-review.googlesource.com/#/c/1670/

This new arrangement will work, even with the App Engine SDK's broken
behavior where it uploads a set of files thinking it's Go 1.2, and
then later compiles those files thinking it's Go 1.4.

Change-Id: Ieb43ebb0925354539f63075b94a63d8e8dede58c
  • Loading branch information
bradfitz committed Jan 12, 2015
1 parent 44a4e99 commit 226d58f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 39 deletions.
34 changes: 0 additions & 34 deletions compute/metadata/go12.go

This file was deleted.

10 changes: 6 additions & 4 deletions compute/metadata/go13.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ import (
//
// TODO(bradfitz,jbd,adg): remove this once App Engine supports Go
// 1.3+.
func metaClientDialer() *net.Dialer {
return &net.Dialer{
Timeout: 750 * time.Millisecond,
KeepAlive: 30 * time.Second,
func init() {
go13Dialer = func() *net.Dialer {
return &net.Dialer{
Timeout: 750 * time.Millisecond,
KeepAlive: 30 * time.Second,
}
}
}
22 changes: 21 additions & 1 deletion compute/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"net"
"net/http"
"strings"
"sync"
Expand All @@ -47,12 +48,31 @@ var (
var metaClient = &http.Client{
Transport: &internal.Transport{
Base: &http.Transport{
Dial: metaClientDialer().Dial,
Dial: dialer().Dial,
ResponseHeaderTimeout: 750 * time.Millisecond,
},
},
}

// go13Dialer is nil until we're using Go 1.3+.
// This is a workaround for https://github.com/golang/oauth2/issues/70, where
// net.Dialer.KeepAlive is unavailable on Go 1.2 (which App Engine as of
// Jan 2015 still runs).
//
// TODO(bradfitz,jbd,adg,dsymonds): remove this once App Engine supports Go
// 1.3+ and go-app-builder also supports 1.3+, or when Go 1.2 is no longer an
// option on App Engine.
var go13Dialer func() *net.Dialer

func dialer() *net.Dialer {
if fn := go13Dialer; fn != nil {
return fn()
}
return &net.Dialer{
Timeout: 750 * time.Millisecond,
}
}

// Get returns a value from the metadata service.
// The suffix is appended to "http://metadata/computeMetadata/v1/".
func Get(suffix string) (string, error) {
Expand Down

0 comments on commit 226d58f

Please sign in to comment.