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

kiwix::Downloader's constructor pauses all downloads found in the aria session file #1097

Merged
merged 4 commits into from
Jul 8, 2024

Conversation

veloman-yunkan
Copy link
Collaborator

This PR addresses one of the problems observed while working on kiwix/kiwix-desktop#1118. See the commit messages for details.

Copy link

codecov bot commented Jun 28, 2024

Codecov Report

Attention: Patch coverage is 0% with 32 lines in your changes missing coverage. Please review.

Project coverage is 41.21%. Comparing base (af96b19) to head (65a777d).
Report is 83 commits behind head on main.

Files with missing lines Patch % Lines
src/aria2.cpp 0.00% 26 Missing ⚠️
src/downloader.cpp 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1097      +/-   ##
==========================================
- Coverage   41.45%   41.21%   -0.25%     
==========================================
  Files          58       58              
  Lines        4233     4258      +25     
  Branches     2316     2332      +16     
==========================================
  Hits         1755     1755              
- Misses        989     1014      +25     
  Partials     1489     1489              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@mgautierfr mgautierfr 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 a nice improvement if you have finally found the slow down of all those downloads in kiwix-desktop !!

I have few comments, which may imply a change or not.

if ( !startsWith(line, " pause=") ) {
ss << line << "\n";
}
if ( !line.empty() && line[0] != ' ' && line[0] != '#' ) {
Copy link
Member

Choose a reason for hiding this comment

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

With line[0] != ' ', you are checking that line doesn't start with ' ',
but " pause=" is starting by a space.

Is there something wrong ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, everything is correct. The aria2c input file can contain a list of URIs with options specified after each line of URIs (these optional lines must start with white space(s)). Lines starting with # are treated as comments and skipped.

In other words, a commentless aria2 input file looks like below:

URI1
 option11
 option12
 ...
URI2
 option21
 option22
 ...

The expression under question evaluates to true (only) for URI lines. As soon as such a line is read (and output by the preceding statement) a pause=true option is appended after it.

src/aria2.cpp Outdated
Comment on lines 130 to 132
MethodCall methodCall("aria2.pauseAll", m_secret);
doRequest(methodCall);

Copy link
Member

Choose a reason for hiding this comment

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

Do we really need the first commit adding this ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I had the same question, and I chose to keep this change because it contributes to a more gradual way of explaining the problem and leading to (and justifying) the most robust solution.

@kelson42 kelson42 added this to the 13.2.0 milestone Jun 28, 2024
@veloman-yunkan
Copy link
Collaborator Author

This is a nice improvement if you have finally found the slow down of all those downloads in kiwix-desktop !!

This PR is a relatively insignificant part of the total effort put into kiwix/kiwix-desktop#1118 - here I address only quite non typical scenarios when kiwix-desktop is terminated with active downloads still running. But since the problem was discovered I couldn't ignore it. And as the fix is self-contained (doesn't depend on anything else) and belongs to a different repository, I filed this PR separately as an appetizer ahead of the main meal bound to be served next week. 😄

@veloman-yunkan
Copy link
Collaborator Author

Further testing revealed a bug with exception safety of destructors which is now fixed in a fixup commit.

veloman-yunkan added a commit to kiwix/kiwix-desktop that referenced this pull request Jun 30, 2024
veloman-yunkan added a commit to kiwix/kiwix-desktop that referenced this pull request Jun 30, 2024
@kelson42
Copy link
Collaborator

@veloman-yunkan @mgautierfr So I guess this PR need new review?

@veloman-yunkan
Copy link
Collaborator Author

@kelson42 An approval was still due, so getting one will now simply require looking at a relatively small change.

@kelson42 kelson42 requested a review from mgautierfr June 30, 2024 16:40
@kelson42
Copy link
Collaborator

@veloman-yunkan Great, it is still helpful to reask for review (click on the refresh logo) so there is no ambiguity.

@mgautierfr
Copy link
Member

Seems good to me. Please rebase-fixup and merge directly.

Otherwise, creating a Downloader object next time may take very long (or
that operation may get stuck) if an active download is being saved to slow
media.
Downloader constructor may get stuck if the check for the aria2c RPC
being up gets stuck due to curl_easy_perform() never returning (or, at
least, taking longer than I was willing to wait). Currently it may
happen, for example, after an application crashes with active downloads
being saved to slow media. Then the next creation of a Downloader object
will deal with aria2c immediately resuming those downloads and becoming
unresponsive as it struggles flushing incoming data to slow storage (or
because of some other unfortunate timing of the RPC request being
received while it cannot yet be served).
The aria session file is edited before starting aria2c. This ensures
responsive aria2c RPC server even after a crash.
@veloman-yunkan veloman-yunkan merged commit ece4096 into main Jul 8, 2024
15 of 16 checks passed
@veloman-yunkan veloman-yunkan deleted the robust_download_management branch July 8, 2024 16:26
veloman-yunkan added a commit to kiwix/kiwix-desktop that referenced this pull request Jul 9, 2024
veloman-yunkan added a commit to kiwix/kiwix-desktop that referenced this pull request Jul 10, 2024
veloman-yunkan added a commit to kiwix/kiwix-desktop that referenced this pull request Jul 15, 2024
kelson42 pushed a commit to kiwix/kiwix-desktop that referenced this pull request Jul 19, 2024
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