writeErrCh := make(chan error, 1) // 有缓冲
pc.writech <- writeRequest{req, writeErrCh, continueCh}
resc := make(chan responseAndError) // 无缓冲
pc.reqch <- requestAndChan{
req: req.Request,
ch: resc,
addedGzip: requestedGzip,
continueCh: continueCh,
callerGone: gone,
}
golang标准库里,http.net.persistConn 结构的 roundTrip 函数里。为什么 responseAndError 要用无缓冲队列。因此每次写 responseAndError 同时还要判断 callerGone 队列?
//
type requestAndChan struct {
req *Request
ch chan responseAndError // unbuffered; always send in select on callerGone
}
按照当时fix说明其中一个原因应该是为了防止goroutine泄露
https://go-review.googlesourc...
但是看现在的逻辑,好像使用有缓冲的也不会出问题