Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ internals.writeFile = function (req, options, stream) {
unpipeStreamToCounter();
unpipeCounterToFile();

file.destroy();
file.close();
Fs.unlink(path, (/* fsErr */) => reject(err)); // Ignore unlink errors
return;
}
Expand Down
15 changes: 12 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,7 @@ describe('parse()', () => {
expect(fileContents.toString('binary') === buffer.toString('binary')).to.equal(true);
});

it('cleans file when stream is aborted', { retry: true }, async () => {
it('cleans file when stream is aborted', async () => {

const path = Path.join(__dirname, 'file');
const count = Fs.readdirSync(path).length;
Expand All @@ -1304,16 +1304,25 @@ describe('parse()', () => {
};

const req = Http.request(options, (res) => { });
req.on('error', Hoek.ignore);
const random = Buffer.alloc(100000);
req.write(random);
req.write(random);

await Hoek.wait(500);
req.abort();
req.destroy();

let error;
req.once('error', (err) => (error = err));

const incoming = await receive;
await expect(Subtext.parse(incoming, null, { parse: false, output: 'file', uploads: path })).to.reject(/Client connection aborted/);

if (error) {
// For some reason the stream can error _after_ being destroyed...

expect(error).to.contain({ code: 'ECONNRESET' }).and.be.an.error();
}

expect(Fs.readdirSync(path).length).to.equal(count);
});

Expand Down
Loading