Created
June 6, 2018 08:32
-
-
Save myitcv/3d3be2b2647d0b5a2b689e9b5fea078e to your computer and use it in GitHub Desktop.
GopherJS "leaking" repro
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
// this program demonstrates how fetches through gopherjs seem to be memory leaking. | |
package main | |
import ( | |
"fmt" | |
"io" | |
"io/ioutil" | |
"log" | |
"net/http" | |
"github.com/gopherjs/gopherjs/js" | |
) | |
func main() { | |
js.Global.Set("gocode", map[string]interface{}{ | |
"fetch": fetch, | |
}) | |
} | |
const ( | |
maxFetch = 10000 | |
fetchURL = "playground_gopherjs.js" | |
) | |
func fetch() { | |
go func() { | |
for i := 0; i < maxFetch; i++ { | |
fmt.Printf("Getting\n") | |
req, err := http.NewRequest("GET", fetchURL, nil) | |
if err != nil { | |
log.Fatal(err) | |
} | |
res, err := http.DefaultClient.Do(req) | |
if err != nil { | |
log.Fatal(err) | |
} | |
func() { | |
defer res.Body.Close() | |
if _, err := io.Copy(ioutil.Discard, res.Body); err != nil { | |
log.Fatal(err) | |
} | |
}() | |
} | |
}() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment