Skip to content

Conversation

@minfaer
Copy link
Contributor

@minfaer minfaer commented Sep 4, 2021

Fix nextcloud/android#5609
Fix nextcloud/android#8134

This is a fix for nextcloud/android#5609 as proposed in #696.
It works by setting the read timeout for the move-method that assembles chunk-uploads on the server to 3 minutes per GB between 30 seconds and 30 minutes, consistent with Nextcloud-dektop.

Set read timeout for the move-method that assembles chunk-uploads on the server to 3 minutes per GB between 30 seconds and 30 minutes, consistent with Nextcloud-dektop.

Signed-off-by: M. Thees <m.thees@intempestatem.eu>
moveMethod.addRequestHeader(E2E_TOKEN, token);
}
int moveResult = client.executeMethod(moveMethod);
int moveResult = client.executeMethod(moveMethod, CalcAssembleTimeout(file), -1);
Copy link
Member

Choose a reason for hiding this comment

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

For -1 can you introduce a const, e.g. DO_NOT_CHANGE_DEFAULT, so that when reading the code one directly knows that this value does not change connection timeout.

final double threeMinutes = 3.0 * 60 * 1000;
final int thirtySeconds = 30 * 1000;
final int thirtyMinutes = 30 * 60 * 1000;
int AssembleReadTimeout = Math.max(thirtySeconds , Math.min((int)(threeMinutes * file.length() / 1e9) , thirtyMinutes) );
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
int AssembleReadTimeout = Math.max(thirtySeconds , Math.min((int)(threeMinutes * file.length() / 1e9) , thirtyMinutes) );
return Math.max(thirtySeconds , Math.min((int)(threeMinutes * file.length() / 1e9) , thirtyMinutes) );

Copy link
Member

Choose a reason for hiding this comment

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

I'd also suggest extracting file.length() / 1e9 into a new variable named fileSizeInGb to make it easier to read and make the algorithm clearer.

@tobiasKaminsky
Copy link
Member

@minfaer thanks for your PR 🎉
If you have time it would be really great if you can write some unit tests in

Different file sizes:

  • 0b
  • 100b
  • 100 Mb
  • 1 Gb
  • 2 Gb
  • 50 Gb
  • 500 Gb

If you do not have time, then we will take care of it :)

@AlvaroBrey AlvaroBrey closed this Sep 7, 2021
@AlvaroBrey AlvaroBrey reopened this Sep 7, 2021
}

private int CalcAssembleTimeout(File file) {
final double threeMinutes = 3.0 * 60 * 1000;
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this needs to be a double, an int should work fine.

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 the original version, this was a double to prevent threeMinutes * file.length() / 1e9 from truncating to full Gb, but by declaring fileSizeInGb as double, this has indeed become unnecessary.

final double threeMinutes = 3.0 * 60 * 1000;
final int thirtySeconds = 30 * 1000;
final int thirtyMinutes = 30 * 60 * 1000;
int AssembleReadTimeout = Math.max(thirtySeconds , Math.min((int)(threeMinutes * file.length() / 1e9) , thirtyMinutes) );
Copy link
Member

Choose a reason for hiding this comment

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

I'd also suggest extracting file.length() / 1e9 into a new variable named fileSizeInGb to make it easier to read and make the algorithm clearer.

@AlvaroBrey
Copy link
Member

Sorry for the close and reopen, my fingers slipped 🤦 I've added a couple of minor comments. Thanks for your contribution!

minfaer and others added 2 commits September 7, 2021 12:45
Co-authored-by: Tobias Kaminsky <tobias@nextcloud.com>
Signed-off-by: M. Thees <m.thees@intempestatem.eu>
Signed-off-by: M. Thees <m.thees@intempestatem.eu>
@minfaer
Copy link
Contributor Author

minfaer commented Sep 7, 2021

Thank You @tobiasKaminsky and @AlvaroBrey for Your feedback! I implemented your suggestionsand am looking into writing the unit-tests.

@codecov
Copy link

codecov bot commented Sep 7, 2021

Codecov Report

Merging #709 (415acf0) into master (b89ecd3) will decrease coverage by 0.04%.
The diff coverage is 0.00%.

❗ Current head 415acf0 differs from pull request most recent head e1c7695. Consider uploading reports for the commit e1c7695 to get more accurate results

@@            Coverage Diff             @@
##           master     #709      +/-   ##
==========================================
- Coverage   44.54%   44.49%   -0.05%     
==========================================
  Files         154      154              
  Lines        6174     6180       +6     
  Branches      813      813              
==========================================
  Hits         2750     2750              
- Misses       3003     3009       +6     
  Partials      421      421              
Impacted Files Coverage Δ
...ources/files/ChunkedFileUploadRemoteOperation.java 0.00% <0.00%> (ø)

@m-terlinde
Copy link

Thanks @minfaer for this suggested patch!
Since this issue is bugging me for month, I'd love to see the patch in production.

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
@tobiasKaminsky
Copy link
Member

I added tests and once CI is passed, we can merge it.
Thanks @minfaer

@nextcloud-android-bot
Copy link
Collaborator

Lint

TypemasterPR
Warnings22
Errors00

SpotBugs (new)

Warning Type Number
Bad practice Warnings 14
Correctness Warnings 38
Internationalization Warnings 6
Malicious code vulnerability Warnings 7
Multithreaded correctness Warnings 3
Performance Warnings 13
Security Warnings 1
Dodgy code Warnings 40
Total 122

SpotBugs (master)

Warning Type Number
Bad practice Warnings 14
Correctness Warnings 38
Internationalization Warnings 6
Malicious code vulnerability Warnings 7
Multithreaded correctness Warnings 3
Performance Warnings 13
Security Warnings 1
Dodgy code Warnings 40
Total 122

@nextcloud-android-bot
Copy link
Collaborator

@AlvaroBrey
Copy link
Member

stable-IT test failed: https://www.kaminsky.me/nc-dev/library-integrationTests/560-IT-stable-09-37

Checked this out locally, nothing to worry about. Thanks for your contribution @minfaer !

@AlvaroBrey AlvaroBrey merged commit 3d0834d into nextcloud:master Oct 18, 2021
@AlvaroBrey AlvaroBrey added this to the NC Android lib 2.8.0 milestone Oct 18, 2021
@szaimen
Copy link
Contributor

szaimen commented Oct 18, 2021

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nextcloud fails to register large autouploads as uploaded upload of large files fails with connection error

6 participants