Skip to content

Commit 182b736

Browse files
committed
prevent race condition
1 parent 9ee16e2 commit 182b736

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Diff for: transport/http_client.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,22 +115,22 @@ func (h *httpTransportClient) Recv(msg *Message) (err error) {
115115
var rc *http.Request
116116
var ok bool
117117

118+
h.Lock()
118119
select {
119120
case rc, ok = <-h.req:
120121
default:
121122
}
122123

123124
if !ok {
124-
h.Lock()
125125
if len(h.reqList) == 0 {
126126
h.Unlock()
127127
return io.EOF
128128
}
129129

130130
rc = h.reqList[0]
131131
h.reqList = h.reqList[1:]
132-
h.Unlock()
133132
}
133+
h.Unlock()
134134

135135
req = rc
136136
}

0 commit comments

Comments
 (0)