Handle a case where transfers channel was not closed properly.
This commit is contained in:
@@ -75,6 +75,9 @@ func (r ReadStream) Read(p []byte) (int, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
// wait error aborts immediately, all remaining data is invalid.
|
// wait error aborts immediately, all remaining data is invalid.
|
||||||
t.free()
|
t.free()
|
||||||
|
if s.delayedErr == nil {
|
||||||
|
close(s.transfers)
|
||||||
|
}
|
||||||
for t := range s.transfers {
|
for t := range s.transfers {
|
||||||
t.cancel()
|
t.cancel()
|
||||||
t.wait()
|
t.wait()
|
||||||
|
@@ -198,6 +198,18 @@ func TestReadStream(t *testing.T) {
|
|||||||
{err: io.ErrClosedPipe},
|
{err: io.ErrClosedPipe},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "fail quickly",
|
||||||
|
transfers: [][]fakeStreamResult{
|
||||||
|
{{waitErr: sentinelError}},
|
||||||
|
{{n: 500}},
|
||||||
|
{{n: 500}},
|
||||||
|
},
|
||||||
|
want: []readRes{
|
||||||
|
{err: sentinelError},
|
||||||
|
{err: io.ErrClosedPipe},
|
||||||
|
},
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(strconv.Itoa(tcNum), func(t *testing.T) {
|
t.Run(strconv.Itoa(tcNum), func(t *testing.T) {
|
||||||
t.Logf("Case %d: %s", tcNum, tc.desc)
|
t.Logf("Case %d: %s", tcNum, tc.desc)
|
||||||
|
Reference in New Issue
Block a user