Closed jjacquay712 closed 8 years ago
Serving file over HTTP causes massive memory leak:
func main() { irods, err := gorods.New(gorods.ConnectionOptions { Type: gorods.UserDefined, Host: "localhost", Port: 1247, Zone: "tempZone", Username: "admin", Password: "-redacted-", }) if err != nil { fmt.Printf("Error connecting to server: %v\n", err) os.Exit(1) } homeDir, err := irods.Collection("/tempZone/home/admin", false) if err != nil { p(err) os.Exit(1) } fileForDownload := homeDir.Get("centos.iso") r := mux.NewRouter() // Routes consist of a path and a handler function. r.HandleFunc("/", func (w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Disposition", "attachment; filename=centos.iso") w.Header().Set("Content-type", "application/octet-stream") w.Header().Set("Content-Length", strconv.FormatInt(fileForDownload.Size, 10)) fileForDownload.ReadChunk(4096, func(chunk []byte) { w.Write(chunk) }) }) l, err := net.Listen("tcp4", ":8080") if err != nil { log.Fatal(err) } log.Fatal(http.Serve(l, r)) }
Serving file over HTTP causes massive memory leak: