Skip to content

Commit aa7c9d9

Browse files
ktockKern Walster
authored andcommitted
Fix pull fails on unexpected EOF
Currently, containerd doesn't restart pull when it encounters unexpected EOF of blob strem withtout error codes. There are cases where this lead to pull failure. This commit tries to fix this issue. Signed-off-by: Kohei Tokunaga <[email protected]> (cherry picked from commit 7bc5aa7) Signed-off-by: Kern Walster <[email protected]>
1 parent c41d458 commit aa7c9d9

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

remotes/docker/httpreadseeker.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,16 @@ import (
2626
"github.com/pkg/errors"
2727
)
2828

29+
const maxRetry = 3
30+
2931
type httpReadSeeker struct {
3032
size int64
3133
offset int64
3234
rc io.ReadCloser
3335
open func(offset int64) (io.ReadCloser, error)
3436
closed bool
37+
38+
errsWithNoProgress int
3539
}
3640

3741
func newHTTPReadSeeker(size int64, open func(offset int64) (io.ReadCloser, error)) (io.ReadCloser, error) {
@@ -53,6 +57,27 @@ func (hrs *httpReadSeeker) Read(p []byte) (n int, err error) {
5357

5458
n, err = rd.Read(p)
5559
hrs.offset += int64(n)
60+
if n > 0 || err == nil {
61+
hrs.errsWithNoProgress = 0
62+
}
63+
if err == io.ErrUnexpectedEOF {
64+
// connection closed unexpectedly. try reconnecting.
65+
if n == 0 {
66+
hrs.errsWithNoProgress++
67+
if hrs.errsWithNoProgress > maxRetry {
68+
return // too many retries for this offset with no progress
69+
}
70+
}
71+
if hrs.rc != nil {
72+
if clsErr := hrs.rc.Close(); clsErr != nil {
73+
log.L.WithError(clsErr).Errorf("httpReadSeeker: failed to close ReadCloser")
74+
}
75+
hrs.rc = nil
76+
}
77+
if _, err2 := hrs.reader(); err2 == nil {
78+
return n, nil
79+
}
80+
}
5681
return
5782
}
5883

0 commit comments

Comments
 (0)