首页 > 技术文章 > [Golang] http.Post导致goroutine泄漏

mrblue 2019-06-12 11:15 原文

记录一个用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() // 必须要关闭
}

  

 

推荐阅读