Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
This can be used to reproduce EOF errors while using GitHubs API, because GitHub closes keep-alive connections after 60s.
package main
import (
func main() {
bodyString := "{\"query\":\"\\nfragment RepositoryFields on Repository {\\n\\tid\\n\\tdatabaseId\\n\\tnameWithOwner\\n\\tdescription\\n\\turl\\n\\tisPrivate\\n\\tisFork\\n\\tisArchived\\n\\tviewerPermission\\n}\\n\\tquery {\\nrepo0: repository(owner: \\\"sourcegraph\\\", name: \\\"sourcegraph\\\") { ... on Repository { ...RepositoryFields } }\\n}\",\"variables\":{}}"
for {
log.Println("Sending new request ---------------------------")
body := ioutil.NopCloser(bytes.NewBufferString(bodyString))
headers := make(http.Header)
headers.Add("User-Agent", "Go-http-client/1.1")
headers.Add("Authorization", "bearer TOKEN")
headers.Add("Content-Type", "application/json; charset=utf-8")
req := &http.Request{
Method: "POST",
Body: body,
URL: &url.URL{
Scheme: "https",
Host: "",
Path: "/graphql",
RawQuery: "",
Header: headers,
trace := &httptrace.ClientTrace{
GotConn: func(connInfo httptrace.GotConnInfo) {
fmt.Printf("Got Conn: %+v\n", connInfo)
req = req.WithContext(httptrace.WithClientTrace(req.Context(), trace))
resp, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Printf("err=%+v\n", err)
defer resp.Body.Close()
io.Copy(ioutil.Discard, resp.Body)
time.Sleep(time.Duration(60) * time.Second)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.