Skip to content

Commit 8d7aeaa

Browse files
committed
Avoid unhandled rejection on cleanup failure, fix test flakiness
1 parent 91a291c commit 8d7aeaa

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lib/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ internals.multipart = function (req, options, source, contentType) {
239239

240240
const onError = (err) => {
241241

242-
internals.cleanupFiles(pendingFiles);
242+
const cleanup = internals.cleanupFiles(pendingFiles);
243+
cleanup.catch(Hoek.ignore); // Prevent triggering node's PromiseRejectionHandledWarning
244+
243245
reject(Boom.badRequest('Invalid multipart payload format', err));
244246
};
245247

test/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ describe('parse()', () => {
956956
await expect(Subtext.parse(request, null, { parse: true, output: 'file', uploads: '/no/such/folder/a/b/c' })).to.reject(/no.such.folder/);
957957
});
958958

959-
it('cleans-up written files on error', async (flags) => {
959+
it('cleans-up written files on error', { retry: true }, async (flags) => {
960960

961961
const body =
962962
'--AaB03x\r\n' +
@@ -999,7 +999,7 @@ describe('parse()', () => {
999999

10001000
expect(files.length).to.equal(3);
10011001

1002-
await Hoek.wait(10); // Allow time for cleanup to occur
1002+
await Hoek.wait(15); // Allow time for cleanup to occur
10031003
for (const file of files) {
10041004
await expect(Fsp.readFile(file)).to.reject(/ENOENT/);
10051005
}
@@ -1317,7 +1317,7 @@ describe('parse()', () => {
13171317
expect(Fs.readdirSync(path).length).to.equal(count);
13181318
});
13191319

1320-
it('will timeout correctly for a multipart payload with output as stream', async () => {
1320+
it('will timeout correctly for a multipart payload with output as stream', { retry: true }, async () => {
13211321

13221322
const path = Path.join(__dirname, './file/image.jpg');
13231323
const fileStream = Fs.createReadStream(path);

0 commit comments

Comments
 (0)