etcd: fix data race in transporter

This commit is contained in:
Xiang Li 2014-07-10 20:58:54 -07:00 committed by Yicheng Qin
parent 3f435571d3
commit 284e76f0da

View File

@ -87,11 +87,11 @@ func (t *transporter) send(addr string, data []byte) error {
t.mu.RUnlock()
return fmt.Errorf("transporter stopped")
}
t.wg.Add(1)
defer t.wg.Done()
t.mu.RUnlock()
buf := bytes.NewBuffer(data)
t.wg.Add(1)
defer t.wg.Done()
resp, err := t.client.Post(addr, "application/octet-stream", buf)
if err != nil {
return err
@ -148,7 +148,10 @@ func (t *transporter) serveCfg(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
if u, ok := t.urls[id]; ok {
t.mu.RLock()
u, ok := t.urls[id]
t.mu.RUnlock()
if ok {
w.Write([]byte(u))
return
}