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

only add requestFile to tmpUploads if it is not rejected by busboy #171

Merged
merged 7 commits into from
Oct 21, 2020
Merged

only add requestFile to tmpUploads if it is not rejected by busboy #171

merged 7 commits into from
Oct 21, 2020

Conversation

bmo-at
Copy link
Contributor

@bmo-at bmo-at commented Oct 21, 2020

Checklist

PASS test/multipart-big-stream.test.js 3 OK 254.126ms
PASS test/multipart-concat.test.js 9 OK 256.44ms
PASS test/legacy/multipart.test.js 43 OK 446.868ms
PASS test/multipart-body-schema.test.js 8 OK 374.937ms
PASS test/multipart-attach-body.test.js 16 OK 312.564ms
PASS test/legacy/append-body.test.js 74 OK 1s
PASS test/multipart-disk.test.js 42 OK 527.466ms
PASS test/multipart-security.test.js 8 OK 283.763ms
PASS test/multipart-small-stream.test.js 2 OK 141.19ms
PASS test/multipart.test.js 68 OK 459.869ms
PASS test/big.test.js 9 OK 9s
PASS test/legacy/big.test.js 12 OK 12s

🌈 SUMMARY RESULTS 🌈

Suites: 12 passed, 12 of 12 completed
Asserts: 294 passed, of 294
Time: 17s
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 97.28 | 90.82 | 100 | 97.23 | |
index.js | 97.28 | 90.82 | 100 | 97.23 |... 80,281,470,488 |
----------|----------|----------|----------|----------|-------------------|

index.js Outdated
requestFiles.push({ ...file, filepath })
// busboy set truncated to true when the configured file size limit was reached
if (file.file.truncated) {
const err = new RequestFileTooLargeError()
err.part = file
throw err
}
// Delay adding the filepath to tmpUploads until the file has been checked for size
this.tmpUploads.push(filepath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add it there to clean up the files after the response.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also opened an issue to explain further why this change is necessary, see #172

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In short: this adds the file to the list to be cleaned up when the response is closed, but by then it is already deleted.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. We remove the file afterward in the catch handler. I propose to leave it as it is but remove the additional unlink operation in the catch case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'm thinking this should be better

index.js Outdated
requestFiles.push({ ...file, filepath })
// busboy set truncated to true when the configured file size limit was reached
if (file.file.truncated) {
const err = new RequestFileTooLargeError()
err.part = file
throw err
}
// Delay adding the filepath to tmpUploads until the file has been checked for size
this.tmpUploads.push(filepath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. We remove the file afterward in the catch handler. I propose to leave it as it is but remove the additional unlink operation in the catch case.

@bmo-at
Copy link
Contributor Author

bmo-at commented Oct 21, 2020

Yeah I was just writing that up, guess you were faster :)

index.js Outdated
this.log.debug({ err }, 'could not delete file')
}

this.log.error(err)
Copy link
Member

@StarpTech StarpTech Oct 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a bit more context makes it easier to know where it failed.

this.log.error({ err }, 'save request file')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Are the object brackets necessary? I added them just in case

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, both should work.

Copy link
Member

@StarpTech StarpTech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit 4b665e0 into fastify:master Oct 21, 2020
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

Successfully merging this pull request may close these issues.

3 participants