rpcenc: Fix double read at eof
This commit is contained in:
@@ -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)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user