rpcenc: Fix double read at eof

This commit is contained in:
Łukasz Magiera
2022-04-28 11:50:51 +02:00
parent 779e923854
commit 43436f7bc8
2 changed files with 15 additions and 7 deletions
+8
View File
@@ -211,6 +211,7 @@ type RpcReader struct {
postBody io.ReadCloser // nil on initial head request
next chan *RpcReader // on head will get us the postBody after sending resStart
mustRedirect bool
eof bool
res chan readRes
beginOnce *sync.Once
@@ -266,6 +267,10 @@ func (w *RpcReader) Read(p []byte) (int, error) {
w.beginPost()
})
if w.eof {
return 0, io.EOF
}
if w.mustRedirect {
return 0, ErrMustRedirect
}
@@ -276,6 +281,9 @@ func (w *RpcReader) Read(p []byte) (int, error) {
n, err := w.postBody.Read(p)
if err != nil {
if err == io.EOF {
w.eof = true
}
w.closeOnce.Do(func() {
close(w.res)
})