Skip to content

Instantly share code, notes, and snippets.

@slava-vishnyakov
Created March 21, 2016 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slava-vishnyakov/a93808d7603057d96282 to your computer and use it in GitHub Desktop.
Save slava-vishnyakov/a93808d7603057d96282 to your computer and use it in GitHub Desktop.
leaky gorequests
package main
import (
"fmt"
"log"
"os"
"os/exec"
"strings"
"time"
"github.com/parnurzeal/gorequest"
)
func testRequest() {
gorequest.New().Get("http://www.google.com").Set("Connection", "close").End()
}
func main() {
for {
go testRequest()
time.Sleep(1 * time.Second)
fmt.Println("Request done, open files =", countOpenFiles())
}
}
func countOpenFiles() int {
out, err := exec.Command("/bin/sh", "-c", fmt.Sprintf("lsof -p %v", os.Getpid())).Output()
if err != nil {
log.Fatal(err)
}
lines := strings.Split(string(out), "\n")
return len(lines) - 1
}
Request done, open files = 15
Request done, open files = 17
Request done, open files = 19
Request done, open files = 21
Request done, open files = 23
Request done, open files = 25
Request done, open files = 27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment