[Golang] http.Post导致goroutine泄漏

记录一个用http.Post的问题

if _, err := http.Post("http://127.0.0.1:8080", "", nil); nil != err {
	panic(err)
}// 会导致goroutine泄漏

  

if resp, err := http.Post("http://127.0.0.1:8080", "", nil); nil != err {
	panic(err)
} else {
	defer resp.Body.Close() // 必须要关闭
}

  

 

posted @ 2019-06-12 11:15  MrBlue  阅读(732)  评论(0编辑  收藏  举报