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

[Bug] goroutine leak in layer store when apply diff with an invalid image tarball #705

Closed
zvier opened this issue Aug 31, 2020 · 0 comments

Comments

@zvier
Copy link
Contributor

zvier commented Aug 31, 2020

A goroutine leak is occurred when imports an invalid image tarball. The invalid image tarball can be made as flows:

touch test.tar
echo 'aaa' >> test.tar

Then use the invalid image tarball as an base image import to the storage and it will return error with 'error adding layer with blob'. But a goroutine is leak at this time.

With go pprof tool(net/http/pprof), we trace the goroutine was blok in github.com/vbatts/tar-split/archive/tar.(*Reader).readHeader .

func (tr *Reader) readHeader() (*Header, *block, error) {
    n, err := io.ReadFull(tr.r, tr.blk[:])   // This is the block point
    ...
}

Because the io.ReadFull will call tr.r.Read() and the tr.r is the read endpoint of a pip which create in NewLogger.

// github.com/containers/storage/pkg/tarlog/tarlogger.go
 func NewLogger(logger func(*tar.Header)) (io.WriteCloser, error) {
      reader, writer := io.Pipe()
      t := &tarLogger{
          writer:     writer,
          closeMutex: new(sync.Mutex),
          closed:     false,
      }
      tr := tar.NewReader(reader)
      ...

So, if the write endpoint of the pip never close, the readHeader will block and lead a goroutine leak. Since io.Pipe is in-memory, close with an defer clause is safety after it created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant