Skip to content

dropbox: fix chunked uploads when size <= chunkSize - #7692

Closed
nielash wants to merge 1 commit into
rclone:masterfrom
nielash:fix-dropbox-chunks
Closed

nielash wants to merge 1 commit into
rclone:masterfrom
nielash:fix-dropbox-chunks

Conversation

@nielash

@nielash nielash commented Mar 25, 2024

Copy link
Copy Markdown
Contributor

What is the purpose of this change?

Before this change, dropbox would read the same bytes twice (exceeding the file size and causing an error) if the total size was known and less than or equal to the chunkSize (i.e. small enough to complete in one chunk). This change fixes the issue.

Was the change discussed in an issue or in the forum before?

No.

Checklist

  • I have read the contribution guidelines.
  • I have added tests for all changes in this PR if appropriate.
  • I have added documentation for the changes if appropriate.
  • All commit messages are in house style.
  • I'm done, this Pull Request is ready for review :-)

Before this change, dropbox would read the same bytes twice (exceeding the file
size and causing an error) if the total size was known and less than or equal to
the chunkSize (i.e. small enough to complete in one chunk). This change fixes
the issue.
@nielash nielash added this to the v1.67 milestone Mar 25, 2024
@nielash
nielash marked this pull request as ready for review March 25, 2024 23:55
@ncw

ncw commented Mar 26, 2024

Copy link
Copy Markdown
Member

How do you trigger this problem?

This was my attempt

echo hello | rclone rcat -vv --streaming-upload-cutoff 0 dropbox:smol.txt

But that didn't work.

I tried uploading small files with batches but that didn't work either.

The fact that no-one has reported it before makes me think it isn't easy to trigger!

@nielash

nielash commented Mar 26, 2024

Copy link
Copy Markdown
Contributor Author

How do you trigger this problem?

We are hitting it on the bisync tests because of this bit of code, which is a workaround for Dropbox's inability to set modtime on an existing object without re-uploading:

err := obj.SetModTime(ctx, date)
if err == fs.ErrorCantSetModTimeWithoutDelete {
// Workaround for dropbox, similar to --refresh-times
err = nil
buf := new(bytes.Buffer)
size := obj.Size()
separator := ""
if size > 0 {
err = operations.Cat(ctx, f, buf, 0, size, []byte(separator))
}
info := object.NewStaticObjectInfo(remote, date, size, true, nil, f)
if err == nil {
_ = obj.Remove(ctx)
_, err = f.Put(ctx, buf, info)
}
}

Here's an example that will trigger it with the updated tests:

go test ./cmd/bisync -case rclone_args -remote TestDropbox: 

Result:

Error:          test step failed
Test:           TestBisyncRemoteRemote/rclone_args
Messages:       step 10 failed: upload failed: expected 19 bytes in input, but have read 38 so far

Note that size%chunkSize would be 19%50331648, which results in 0 chunks and remainder of 19

@nielash

nielash commented Mar 27, 2024

Copy link
Copy Markdown
Contributor Author

Ugh wait... I think the bug is on the test, not in Dropbox. Hold that thought... 🤦‍♂️

nielash added a commit to nielash/rclone that referenced this pull request Mar 27, 2024
This change officially adds bisync to the nightly integration tests for all
backends.

This will be part of giving us the confidence to take bisync out of beta.

A number of fixes have been added to account for features which can differ on
different backends -- for example, hash types / modtime support, empty
directories, unicode normalization, and unimportant differences in log output.
We will likely find that more of these are needed once we start running these
with the full set of remotes.

Additionally, bisync's extremely sensitive tests revealed a few bugs in other
backends that weren't previously covered by other tests. Fixes for those issues
have been submitted on the following separate PRs (and bisync test failures will
be expected until they are merged):

- rclone#7670 memory: fix deadlock in operations.Purge
- rclone#7688 memory: fix incorrect list entries when rooted at subdirectory
- rclone#7690 memory: fix dst mutating src after server-side copy
- rclone#7692 dropbox: fix chunked uploads when size <= chunkSize

Relatedly, workarounds have been put in place for the following backend
limitations that are unsolvable for the time being:

- rclone#3262 drive is sometimes aware of trashed files/folders when it shouldn't be
- rclone#6199 dropbox can't handle emojis and certain other characters
- rclone#4590 onedrive API has longstanding bug for conflictBehavior=replace in
	server-side copy/move
@nielash

nielash commented Mar 27, 2024

Copy link
Copy Markdown
Contributor Author

Ugh wait... I think the bug is on the test, not in Dropbox. Hold that thought... 🤦‍♂️

Ok I fixed the test on #7693. The issue was that operations.Cat was not filtered for a single file, so it was concatenating all the files in the directory. This caused buf to exceed the size passed in, which Dropbox correctly complained about.

I do think there may still be a small bug in dropbox.uploadChunked, as your example command results in lines like:

2024/03/27 04:42:20 DEBUG : smol.txt: Uploading chunk 1/0
2024/03/27 04:42:20 DEBUG : smol.txt: Uploading chunk 2/0

with the numerator exceeding the denominator. But I'm not sure if that is actually causing any harm? So perhaps this should just be closed.

@ncw

ncw commented Mar 27, 2024

Copy link
Copy Markdown
Member

Ugh wait... I think the bug is on the test, not in Dropbox. Hold that thought... 🤦‍♂️

Ok I fixed the test on #7693. The issue was that operations.Cat was not filtered for a single file, so it was concatenating all the files in the directory.

If you have the fs.Object then use operations.Open to open it for reading. If you don't have the object then use f.NewObject to get it first.

This caused buf to exceed the size passed in, which Dropbox correctly complained about.

Whew!

I do think there may still be a small bug in dropbox.uploadChunked, as your example command results in lines like:

2024/03/27 04:42:20 DEBUG : smol.txt: Uploading chunk 1/0
2024/03/27 04:42:20 DEBUG : smol.txt: Uploading chunk 2/0

with the numerator exceeding the denominator. But I'm not sure if that is actually causing any harm? So perhaps this should just be closed.

The /0 are indicating that the length of the file isn't known at that point so we don't know how many chunks we actually have. It isn't particularly nice to look at but it is cosmetic only.

I'll close this then (with some relief that Dropbox uploads are in fact fine!).

@ncw ncw closed this Mar 27, 2024
nielash added a commit that referenced this pull request Mar 27, 2024
This change officially adds bisync to the nightly integration tests for all
backends.

This will be part of giving us the confidence to take bisync out of beta.

A number of fixes have been added to account for features which can differ on
different backends -- for example, hash types / modtime support, empty
directories, unicode normalization, and unimportant differences in log output.
We will likely find that more of these are needed once we start running these
with the full set of remotes.

Additionally, bisync's extremely sensitive tests revealed a few bugs in other
backends that weren't previously covered by other tests. Fixes for those issues
have been submitted on the following separate PRs (and bisync test failures will
be expected until they are merged):

- #7670 memory: fix deadlock in operations.Purge
- #7688 memory: fix incorrect list entries when rooted at subdirectory
- #7690 memory: fix dst mutating src after server-side copy
- #7692 dropbox: fix chunked uploads when size <= chunkSize

Relatedly, workarounds have been put in place for the following backend
limitations that are unsolvable for the time being:

- #3262 drive is sometimes aware of trashed files/folders when it shouldn't be
- #6199 dropbox can't handle emojis and certain other characters
- #4590 onedrive API has longstanding bug for conflictBehavior=replace in
	server-side copy/move
lafkpages pushed a commit to lafkpages/rclone that referenced this pull request Jul 20, 2026
This change officially adds bisync to the nightly integration tests for all
backends.

This will be part of giving us the confidence to take bisync out of beta.

A number of fixes have been added to account for features which can differ on
different backends -- for example, hash types / modtime support, empty
directories, unicode normalization, and unimportant differences in log output.
We will likely find that more of these are needed once we start running these
with the full set of remotes.

Additionally, bisync's extremely sensitive tests revealed a few bugs in other
backends that weren't previously covered by other tests. Fixes for those issues
have been submitted on the following separate PRs (and bisync test failures will
be expected until they are merged):

- rclone#7670 memory: fix deadlock in operations.Purge
- rclone#7688 memory: fix incorrect list entries when rooted at subdirectory
- rclone#7690 memory: fix dst mutating src after server-side copy
- rclone#7692 dropbox: fix chunked uploads when size <= chunkSize

Relatedly, workarounds have been put in place for the following backend
limitations that are unsolvable for the time being:

- rclone#3262 drive is sometimes aware of trashed files/folders when it shouldn't be
- rclone#6199 dropbox can't handle emojis and certain other characters
- rclone#4590 onedrive API has longstanding bug for conflictBehavior=replace in
	server-side copy/move
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.

2 participants