Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new implementation for limiting tcp connections #2259

Merged
merged 4 commits into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions util/contentutil/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ func (r *rc) Read(b []byte) (int, error) {
return n, err
}

func (r *rc) Seek(offset int64, whence int) (int64, error) {
switch whence {
case io.SeekStart:
r.offset = int(offset)
tonistiigi marked this conversation as resolved.
Show resolved Hide resolved
case io.SeekCurrent:
r.offset += int(offset)
case io.SeekEnd:
r.offset = int(r.Size()) - int(offset)
}
return int64(r.offset), nil
}

func CopyChain(ctx context.Context, ingester content.Ingester, provider content.Provider, desc ocispec.Descriptor) error {
var m sync.Mutex
manifestStack := []ocispec.Descriptor{}
Expand Down
10 changes: 10 additions & 0 deletions util/resolver/limited/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func (f *fetcher) Fetch(ctx context.Context, desc ocispec.Descriptor) (io.ReadCl
release()
return nil, err
}

rcw := &readCloser{ReadCloser: rc}
closer := func() {
if !rcw.closed {
Expand All @@ -161,9 +162,18 @@ func (f *fetcher) Fetch(ctx context.Context, desc ocispec.Descriptor) (io.ReadCl
rc.close()
})

if s, ok := rc.(io.Seeker); ok {
return &readCloserSeeker{rcw, s}, nil
}

return rcw, nil
}

type readCloserSeeker struct {
*readCloser
io.Seeker
}

type readCloser struct {
io.ReadCloser
once sync.Once
Expand Down