Skip to content

Cleanup part file after upload exception - #17189

Merged
MorrisJobke merged 2 commits into
masterfrom
files-straypartfilesonexception
Jun 30, 2015
Merged

MorrisJobke merged 2 commits into
masterfrom
files-straypartfilesonexception

Conversation

@PVince81

Copy link
Copy Markdown
Contributor

Fixes #17149

  • write unit tests
  • TEST: upload of small file + permission error on fopen
  • TEST: upload of small file + exception during final rename
  • TEST: upload of small file + exception during stream copy
  • TEST: upload of big file + exception during final rename
  • TEST: upload of big file + exception during chunk assembly

@icewind1991 @MorrisJobke
(I haven't tested this yet)

@PVince81 PVince81 added this to the 8.1-current milestone Jun 26, 2015
@PVince81

Copy link
Copy Markdown
Contributor Author

Added some unit tests for small files.
But I'm not happy in general because we have a lot of exceptions.
We should refactor this to catch any exception and convert it with a new method convertToSabreException() before rethrowing.

Also there are no unit tests for big file chunking, so testing exceptions and part files there will be difficult.

@PVince81

Copy link
Copy Markdown
Contributor Author

@PVince81

Copy link
Copy Markdown
Contributor Author

Raised #17220 to refactor exception handling.

Comment thread lib/private/connector/sabre/file.php Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

hmm - this kind of cries already for the 'global' exception handling/conversion function .... 🙊

refs #17220

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I should patent my Base.php idea:

<?php
try {
// All of base.php
} catch (\Exception $e) {
echo "All fine. Nothing to worry about.";
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🙊 🙉 🙈

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes it does... but I'm afraid to refactor at this point as we don't have enough test coverage... (and also not enough time)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe another idea would be to use a shutdown handler to clear part files. This means they need to be registered somewhere to be cleant up later... might be more complicated.

@PVince81

Copy link
Copy Markdown
Contributor Author

Also to note: I'm writing a bit of unit tests for chunking, because without even some base tests it will be impossible to test chunk clearing...

@PVince81

Copy link
Copy Markdown
Contributor Author

Looks like refactoring will be inevitable: the chunking code path doesn't translate half of the exceptions...

I'll limit the refactoring to the specific try/catch blocks that clean up chunks to limit side-effects.
Ideally in the future all try/catch blocks should have that logic.

@PVince81

Copy link
Copy Markdown
Contributor Author

Ok, I added unit test for the file chunking cases and also refactored exception conversion into a method.

Please have a look and tell me it's a bit saner now...
Will still need some manual testing.

Comment thread lib/private/connector/sabre/file.php Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can you please add the previous exception as third parameter. Makes traces more easy.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, I'll try and modify all the exception classes to accept a $reason argument.

@PVince81

Copy link
Copy Markdown
Contributor Author

Done: I added the previous exception to the constructors

@PVince81

Copy link
Copy Markdown
Contributor Author
  • BUG: part files not deleted for chunk upload with locking enabled

@MorrisJobke

Copy link
Copy Markdown
Contributor
00:36:24.357 There was 1 failure:
00:36:24.357 
00:36:24.357 1) OC\UpdaterTest::testCheckWithEmptyInvalidXmlResponse
00:36:24.357 Expectation failed for method name is equal to <string:setAppValue> when invoked at sequence index 1
00:36:24.357 Parameter 2 for invocation OCP\IConfig::setAppValue('core', 'lastupdatedat', 1435583499) does not match expected value.
00:36:24.357 Failed asserting that 1435583499 matches expected 1435583498.
00:36:24.357 
00:36:24.357 /var/jenkins/workspace/pull-request-analyser-ng-simple@3/label/SLAVE/lib/private/updater.php:135
00:36:24.357 /var/jenkins/workspace/pull-request-analyser-ng-simple@3/label/SLAVE/tests/lib/updater.php:345

@PVince81

Copy link
Copy Markdown
Contributor Author

Ok, the locking issue seems to be that whenever an exception occurs during the final rename in chunking mode, the part file is not getting unlocked yet. So it's not possible to delete it.

Needs further research.
What wonders me is why the unit tests don't catch this case.

@PVince81
PVince81 force-pushed the files-straypartfilesonexception branch from d2da3ae to 621bebd Compare June 29, 2015 14:53
@PVince81

Copy link
Copy Markdown
Contributor Author

Squashed and fixed the unit tests to properly catch the locking exception.

I also added a fix for $view->rename to properly unlock the source path (here the part file), so we can delete it after failure: 621bebd

Vincent Petry added 2 commits June 29, 2015 17:31
Added unit tests for checking for stray part files.
Convert exception to sabre exception in upload put method.

Also added unit test for exception mapping, which also indirectly tests
that the part file is being deleted on exception.

This applies to both chunking and non-chunking mode.

Added some unit tests for chunk upload.
@PVince81
PVince81 force-pushed the files-straypartfilesonexception branch from 621bebd to 167f57c Compare June 30, 2015 08:08
@scrutinizer-notifier

Copy link
Copy Markdown

A new inspection was created.

@PVince81

Copy link
Copy Markdown
Contributor Author

Rebased onto master to avoid the class name issue.

This is ready for review @MorrisJobke @nickvergessen @icewind1991 @DeepDiver1975 @schiesbn

@ghost

ghost commented Jun 30, 2015

Copy link
Copy Markdown

🚀 Test PASSed.🚀
chuck

@icewind1991

Copy link
Copy Markdown
Contributor

Looks good 👍

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since we throw an exception right below, we will end up in the catch where we try to re-unlink the file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

True, missed it. Thanks.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, the stray lock :)

@MorrisJobke

Copy link
Copy Markdown
Contributor

Still works here. There are some additional things I need to debug, but nothing that blocks this and can be done in a followup PR

👍

MorrisJobke added a commit that referenced this pull request Jun 30, 2015
@MorrisJobke
MorrisJobke merged commit 2bcd0af into master Jun 30, 2015
@MorrisJobke
MorrisJobke deleted the files-straypartfilesonexception branch June 30, 2015 09:58
@MorrisJobke

Copy link
Copy Markdown
Contributor

-.- Now github showed my the comments of @nickvergessen

@PVince81

Copy link
Copy Markdown
Contributor Author

Thanks for merging 😄

I'll send a follow up PR for the small stuff.

@MorrisJobke

Copy link
Copy Markdown
Contributor

I'll send a follow up PR for the small stuff.

@PVince81 Ping

@PVince81

PVince81 commented Jul 1, 2015

Copy link
Copy Markdown
Contributor Author

It's on my internal todo list. Was busy with more important locking stuff yesterday.

@PVince81

PVince81 commented Jul 1, 2015

Copy link
Copy Markdown
Contributor Author

Follow up PR here #17268
Please review.

@lock lock Bot locked as resolved and limited conversation to collaborators Aug 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stray part files after failed upload due to locking

7 participants