peer: wait a little before closing idle connections

It seems that it needs some time to set connections that just used
as idle.
This commit is contained in:
Yicheng Qin 2014-08-02 11:17:30 -07:00
parent 611d564865
commit 069a288a59
2 changed files with 5 additions and 1 deletions

View File

@ -122,7 +122,7 @@ func (p *peer) post(d []byte) {
buf := bytes.NewBuffer(d)
resp, err := p.c.Post(p.url, "application/octet-stream", buf)
if err != nil {
log.Println("peer.post url=%s err=\"%v\"", p.url, err)
log.Printf("peer.post url=%s err=\"%v\"", p.url, err)
return
}
resp.Body.Close()

View File

@ -25,6 +25,7 @@ import (
"net/url"
"path"
"sync"
"time"
"github.com/coreos/etcd/raft"
)
@ -77,6 +78,9 @@ func (h *peerHub) stop() {
for _, p := range h.peers {
p.stop()
}
// http.Transport needs some time to put used connections
// into idle queues.
time.Sleep(time.Millisecond)
tr := h.c.Transport.(*http.Transport)
tr.CloseIdleConnections()
}