Refer to the doc, httpclient provides a concurrent-safe as https://github.com/ddliu/go-httpclient#concurrent-safe described,
However there are corner cases where deadlock exists when using httpclient.Begin().PostJson().
How to Reproduce
func Test_httpclient(t *testing.T) {
type Node struct {
Name string `json:"name"`
Next *Node `json:"next"`
}
n1 := Node{Name: "1", Next: nil}
n2 := Node{Name: "2", Next: &n1}
n1.Next = &n2
// send an object that can't be marshalled.
_, err := httpclient.Begin().PostJson("xxx", n2)
if err != nil {
fmt.Println(err.Error())
}
// block here as Begin() can not require the lock.
httpclient.Begin().Get("xxx")
fmt.Println("ok")
}
Problem
Refer to the doc,
httpclient
provides a concurrent-safe as https://github.com/ddliu/go-httpclient#concurrent-safe described, However there are corner cases where deadlock exists when usinghttpclient.Begin().PostJson()
.How to Reproduce
By reading the code further, there are also some other function returned without calling reset() to release the lock, such as https://github.com/ddliu/go-httpclient/blob/d779327486e06c9e47ae2448356941954e95395d/httpclient.go#L729-L754.