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

Clipper, Desktop: Prevent race condition when download limit is reached #10124

Merged
merged 2 commits into from
Mar 20, 2024

Conversation

pedr
Copy link
Collaborator

@pedr pedr commented Mar 14, 2024

The change here is to check if the request.destroy() method has already been called before resolving the fetchBlob function.

This change is necessary to address a potential race condition.

When the LimitedDownloadController calls request.destroy(), it triggers the asynchronous cleanUpOnError function which unlinks the downloaded file and reject. But if before the function is rejected the file.on('finish', ...) is executed the function might appear to resolve successfully, returning a path property to a file that has been unlinked by the cleanUpOnError function.

By checking if request.destroyed is true, we can ensure the file hasn't been unlinked before resolving it.


I think my explanation might be a little confusing, but if needed I can give more information.

@pedr pedr requested a review from laurent22 March 14, 2024 21:47
@laurent22
Copy link
Owner

Thanks Pedro. The pull request title should generally be a user-facing message - what bug that the user was having (or would have had) is fixed by this PR? That's the info that should appear in the title. This is because this message eventually appear in the changelog and user don't know what a "downloadController" is.

@pedr pedr changed the title Clipper, Desktop: Prevents potential bug while downloading files with downloadController Clipper, Desktop: Prevents potential bug that would stop clipper from finishing when download limit was reached Mar 15, 2024
@pedr pedr changed the title Clipper, Desktop: Prevents potential bug that would stop clipper from finishing when download limit was reached Clipper, Desktop: Prevents potential bug when limit is reached Mar 15, 2024
@pedr
Copy link
Collaborator Author

pedr commented Mar 15, 2024

Thanks Pedro. The pull request title should generally be a user-facing message - what bug that the user was having (or would have had) is fixed by this PR? That's the info that should appear in the title. This is because this message eventually appear in the changelog and user don't know what a "downloadController" is.

Sometimes is very hard for me to create a good PR, is this any better?

Clipper, Desktop: Prevents potential bug when limit is reached

@laurent22
Copy link
Owner

Sometimes is very hard for me to create a good PR, is this any better?

I guess you can think of it that way: how would you explain what the feature does to someone who doesn't know much about the codebase, so it means we should avoid things like variable or function names. It needs to give a high level view of the issue - then all that's technical is obviously in the commit itself.

Clipper, Desktop: Prevents potential bug when limit is reached

I would specify what limit - maybe "Prevent race condition when download limit is reached" ?

@pedr pedr changed the title Clipper, Desktop: Prevents potential bug when limit is reached Clipper, Desktop: Prevent race condition when download limit is reached Mar 15, 2024
@laurent22 laurent22 merged commit ea29cf4 into laurent22:dev Mar 20, 2024
10 checks passed
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.

None yet

2 participants