Created
October 28, 2015 21:57
-
-
Save smreed/f1528aa0e7523fda51f9 to your computer and use it in GitHub Desktop.
reproduce goroutine leak in bigtable/client+grpc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"log" | |
"os" | |
"runtime" | |
"time" | |
"golang.org/x/net/context" | |
"golang.org/x/oauth2/google" | |
"google.golang.org/cloud" | |
"google.golang.org/cloud/bigtable" | |
) | |
func main() { | |
if len(os.Args) == 1 { | |
fmt.Println("Usage: go run main.go project zone cluster path-to-json-key table row") | |
os.Exit(1) | |
} | |
project := os.Args[1] | |
zone := os.Args[2] | |
cluster := os.Args[3] | |
key := os.Args[4] | |
table := os.Args[5] | |
row := os.Args[6] | |
jsonKey, _ := ioutil.ReadFile(key) | |
config, _ := google.JWTConfigFromJSON(jsonKey, bigtable.Scope) // or bigtable.AdminScope, etc. | |
ctx := context.Background() | |
client, _ := bigtable.NewClient(ctx, project, zone, cluster, cloud.WithTokenSource(config.TokenSource(ctx))) | |
for _ = range time.Tick(1 * time.Second) { | |
tbl := client.Open(table) | |
r, err := tbl.ReadRow(context.Background(), row) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Printf("row %q: %v, goroutines: %v\n", row, r, runtime.NumGoroutine()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment