Repository navigation
memory: fix deadlock in operations.Purge - #7670
Conversation
ncw
left a comment
There was a problem hiding this comment.
This is very tricky to solve properly!
The problem is that ListR calls out of the backend with the lock held. We can avoid that by accumulating all the entries in memory first (which is a bit wasteful on memory) before calling the function that is passed into ListR with the entries in one go at the end.
There was a problem hiding this comment.
This test should probably be in the internal tests for the memory backend as creating a lot of files will slow down all the integration tests!
There was a problem hiding this comment.
My thought was to check whether any other backends have this same problem (now or in the future) -- although that seems unlikely as this is somewhat specific to memory.
Maybe there's a more efficient way to check it? The reason for creating so many files is that this is basically a race condition which would not occur with fewer files.
There was a problem hiding this comment.
As you've probably noticed I try not to get the integration tests to do too much work! Some backends take several seconds to upload a file so uploading 100 files may increase the run time by 5 minutes for the slow backends.
I think this test is fine, but let's put it in the Internal tests for the memory backend as I think it is unlikely that other backends will have this problem in the future.
There was a problem hiding this comment.
Ok. Full disclosure: bisync's volatile test does something very similar (uploading 100 files) which is how I found this issue originally. Should I put in a condition to skip that test on non-local?
ncw
left a comment
There was a problem hiding this comment.
This is a tricky problem to solve!
I think getting ListR to batch all the entries before calling the callback on them is probably the best solution. Not particularly nice as it uses more memory than it has to but OK...!
I see. Is that better than just removing |
c9fe424 to
41e4599
Compare
ncw
left a comment
There was a problem hiding this comment.
Code looks great now - comments about the test inline.
I don't want to remove ListR for memory as it stands in for a bucket based remote in the tests and they all implement ListR. If this was a normal backend then yes removing it would make perfect sense, but I view it more as an aid to testing.
Thank you :-)
There was a problem hiding this comment.
As you've probably noticed I try not to get the integration tests to do too much work! Some backends take several seconds to upload a file so uploading 100 files may increase the run time by 5 minutes for the slow backends.
I think this test is fine, but let's put it in the Internal tests for the memory backend as I think it is unlikely that other backends will have this problem in the future.
Before this change, the Memory backend had the potential to deadlock under certain conditions, if the ListR callback required locking the b.mu mutex. This was the case with operations.Purge, because Memory has no Purge method, and the fallback option does: err = DeleteFiles(ctx, listToChan(ctx, f, dir)) which potentially starts removing objects before the listing has completed. This change fixes the issue by batching all the entries before calling the callback on them.
41e4599 to
5b630ca
Compare
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
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
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
What is the purpose of this change?
Before this change, the
Memorybackend had the potential to deadlock under certain conditions, if theListRcallback required locking theb.mumutex. This was the case withoperations.Purge, becauseMemoryhas noPurgemethod, and the fallback option does:rclone/fs/operations/operations.go
Line 1126 in ca903b9
which potentially starts removing objects before the listing has completed.
This change fixes the issue by ensuring the mu is unlocked for the duration of
fn.Was the change discussed in an issue or in the forum before?
No.
Checklist