Skip to content

Deadlock in 7.5.14+ with hardlinked files across subdirs #458

Description

@jakebailey

DefinitelyTyped has had this weird hang since May 6th; eventually, I was able to bisect the problem to a patch release in the tar package.

9704d8c seems to contain a bug where the deferred hardlinks deadlock in the PENDINGLINKS queue. Here is a repro that shows the problem for me on Linux:

const { mkdirSync, writeFileSync, linkSync, rmSync } = require('fs');
const { join } = require('path');
const { Pack } = require('tar');

const dir = join(__dirname, 'testdir');
rmSync(dir, { recursive: true, force: true });
mkdirSync(dir);

for (let i = 0; i < 20; i++) {
  const sub = join(dir, `dir${String(i).padStart(3, '0')}`);
  mkdirSync(sub);
  writeFileSync(join(sub, 'file.txt'), `content-${i}`);
}

const src = join(dir, 'dir000', 'hardlink-source.txt');
writeFileSync(src, 'I am the link target');
for (let i = 1; i < 15; i++) {
  linkSync(src, join(dir, `dir${String(i).padStart(3, '0')}`, 'hardlink.txt'));
}

const packer = new Pack({ cwd: __dirname });
packer.add('testdir');
packer.end();

let bytes = 0;
packer.on('data', (chunk) => bytes += chunk.length);
packer.on('end', () => {
  console.log(`OK - Pack finished (${bytes} bytes)`);
  process.exit(0);
});

setTimeout(() => {
  console.log(`HANG - Pack stuck after 5s (read ${bytes} bytes, stream not ended)`);
  process.exit(1);
}, 5000);

I think I can work around it for now, thankfully. The files that were hardlinked were not even supposed to be tar'd in the code we have.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions