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

zero-sized files in tarballs do not call end handler #145

Closed
mattgodbolt opened this issue Jan 2, 2023 · 2 comments
Closed

zero-sized files in tarballs do not call end handler #145

mattgodbolt opened this issue Jan 2, 2023 · 2 comments

Comments

@mattgodbolt
Copy link

If you are extracting an archive with zero-sized files in it, then the stream your entry handler is passed has already been end-ed. This means the on('end') event is not triggered.

Our code looks something like:

extract.on('entry', async (header, stream, next) => {
  //...
    const filestream = fs.createWriteStream(filepath);
    stream
        .on('error', error => {
            logger.error(`Error in stream handling: ${error}`);
            reject(error);
        })
        .on('end', () => {
            next();  /// <--- this handler is never called for zero-sized files, hanging the stream forever
        })
        .pipe(filestream);
    stream.resume();
    if (header.size === 0) next(); //// <--- adding this line "fixes" the issue
@mattgodbolt
Copy link
Author

The stream for empty files is created here:

self.emit('entry', header, emptyStream(self, offset), onunlock)

and the stream has already been ended here:

const emptyStream = function (self, offset) {

so there's no end() event that's emitted after we have had a change to register an on end handler (as best I can tell).

mattgodbolt added a commit to compiler-explorer/compiler-explorer that referenced this issue Jan 2, 2023
It appears that having a zero-sized file won't call our `next()` handler which means we wedge forever and eventually time out.

This is a workaround. Upstream issue filed as mafintosh/tar-stream#145
mattgodbolt added a commit to compiler-explorer/compiler-explorer that referenced this issue Jan 2, 2023
* Handle zero-sized files

It appears that having a zero-sized file won't call our `next()` handler which means we wedge forever and eventually time out.

This is a workaround. Upstream issue filed as mafintosh/tar-stream#145
mattgodbolt added a commit to compiler-explorer/compiler-explorer that referenced this issue Jan 4, 2023
* Handle zero-sized files

It appears that having a zero-sized file won't call our `next()` handler which means we wedge forever and eventually time out.

This is a workaround. Upstream issue filed as mafintosh/tar-stream#145
mattgodbolt added a commit to compiler-explorer/compiler-explorer that referenced this issue Jan 24, 2023
* Handle zero-sized files

It appears that having a zero-sized file won't call our `next()` handler which means we wedge forever and eventually time out.

This is a workaround. Upstream issue filed as mafintosh/tar-stream#145
@mafintosh
Copy link
Owner

Fixed in 3.1.0

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

2 participants