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

Make Downloader threadsafe and more thread compliant. #886

Merged
merged 9 commits into from
Feb 8, 2023
Merged

Conversation

mgautierfr
Copy link
Member

Fix #873

@codecov
Copy link

codecov bot commented Feb 7, 2023

Codecov Report

Base: 72.01% // Head: 71.88% // Decreases project coverage by -0.14% ⚠️

Coverage data is based on head (4903f79) compared to base (2781da3).
Patch coverage: 0.00% of modified lines in pull request are covered.

❗ Current head 4903f79 differs from pull request most recent head 1ba5882. Consider uploading reports for the commit 1ba5882 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #886      +/-   ##
==========================================
- Coverage   72.01%   71.88%   -0.14%     
==========================================
  Files          53       54       +1     
  Lines        3745     3752       +7     
  Branches     2093     2100       +7     
==========================================
  Hits         2697     2697              
- Misses       1046     1053       +7     
  Partials        2        2              
Impacted Files Coverage Δ
include/downloader.h 0.00% <0.00%> (ø)
src/aria2.cpp 0.00% <0.00%> (ø)
src/aria2.h 0.00% <0.00%> (ø)
src/downloader.cpp 0.00% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Collaborator

@veloman-yunkan veloman-yunkan left a comment

Choose a reason for hiding this comment

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

This is the first time I look at the kiwix::Downloader code and, IMO, it will benefit from some extra refactoring/cleanup. Also it might be a good opportunity to replace libcurl with httplib.

However, since this PR immediately addresses a user problem it makes sense to merge it quickly (after the concern about the semantic change in the API is resolved) and discuss the proposed improvements without any haste.

include/downloader.h Outdated Show resolved Hide resolved
src/downloader.cpp Outdated Show resolved Hide resolved
src/downloader.cpp Outdated Show resolved Hide resolved
include/downloader.h Outdated Show resolved Hide resolved
Copy link
Collaborator

@veloman-yunkan veloman-yunkan left a comment

Choose a reason for hiding this comment

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

Please rebase&fixup, fix the commit and PR titles and we should be good to merge.

@mgautierfr mgautierfr changed the title Make Download threadsafe and more thread compliant. Make Downloader threadsafe and more thread compliant. Feb 8, 2023
As we now build a new request handle for every request, we don't need
a lock.

libcurl itself is thread safe as long as we don't share a handle.
User may already have a pointer to the `Download` and it is not protected
against concurrent access.

We could update the status of new created `Download` as by definition,
no one have a pointer on it.
But it better to not do it neither :
- For consistency
- Because the first call on update status may be long on windows (because
  of file preallocation). It is better to not block the downloader for that.
This is dangerous by nature to return raw pointer on internal data.
`false` is a pretty bad default value as most user want to track
the real download.

By removing the default value, we force user to make a choice.
We could have change the default value to true but it would have been
a silent API change and we don't want that.
`Waiting` can become `Active` while we are getting the downloads.
We may have rare case where we miss a download if we get `Active` before
`Waiting`.
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.

Make aria2 wrapper and Downloader thread safe/compliant.
2 participants