Skip to content

Acquire locks before post-hooks, release afterwards #16829

Closed

Description

@PVince81

@icewind1991 @DeepDiver1975
Let the discussion about acquiring locks in the prehooks continue here.

Some arguments here: #16727 (comment)

Activity

  1. added this to the milestone on Jun 9, 2015
  2. PVince81 commented on Jun 9, 2015

    @PVince81
    ContributorAuthor

    Marking as bug as this is a potential bug.
    Might be possible to trigger this somehow with carefully placed "sleep()" statements.

  3. icewind1991 commented on Jun 9, 2015

    @icewind1991
    Contributor

    We already lock around pre-hooks, it's post-hooks that I'm unsure off

  4. PVince81 commented on Jun 9, 2015

    @PVince81
    ContributorAuthor

    Right, post-hooks.

    Would it hurt to lock there ? Any negative consequences that comes to mind ?

  5. changed the title [-]Acquire locks before prehooks[/-] [+]Acquire locks after post-hooks[/+] on Jun 9, 2015
  6. changed the title [-]Acquire locks after post-hooks[/-] [+]Acquire locks before post-hooks, release afterwards[/+] on Jun 9, 2015
  7. icewind1991 commented on Jun 9, 2015

    @icewind1991
    Contributor

    if we lock around post-hooks then hooks can no longer write to the file.

    I'm not sure if we currently have any hooks that write to the file but we have had those in the past and I would say there are valid use cases for it

  8. PVince81 commented on Jun 9, 2015

    @PVince81
    ContributorAuthor

    Hmm ok, so it means if an app really would do something with the file in a post-hook, it would go over the view anyway and re-lock the file.

    Only if someone would rename/move away the file between the operation and the post-hook, then shit could happen.

    I'll try and find a concrete case with reproduction steps then.

  9. PVince81 commented on Jun 12, 2015

    @PVince81
    ContributorAuthor

    Steps:

    1. Create a folder "folder"
    2. Create a file "folder/test.txt"
    3. Edit "folder/test.txt" multiple times to create versions.
    4. Add a "sleep(10);" in versions post rename hook before the "renameOrCopy" call: https://github.com/owncloud/core/blob/master/apps/files_versions/lib/hooks.php#L103
    5. Rename "folder/test.txt" to "folder/re.txt"
    6. In another window or WebDAV, rename "folder" to "re"
    7. Wait for all operations to finish
    8. Check the versions of "re/re.txt"

    The versions are still there. The reason is because renaming the folder also triggered the version copying logic, so this might be sheer luck.

    However the file rename fails with 500, logs contain this:

    {"reqId":"E6zC8T1E4xL1Sej3uG5G","remoteAddr":"127.0.0.1","app":"PHP","message":"Argument 1 passed to OCA\\Files\\Helper::formatFileInfo() must implement interface OCP\\Files\\FileInfo, boolean given, called in \/srv\/www\/htdocs\/owncloud\/apps\/files\/lib\/app.php on line 122 and defined at \/srv\/www\/htdocs\/owncloud\/apps\/files\/lib\/helper.php#135","level":3,"time":"2015-06-12T13:44:55+00:00","method":"GET","url":"\/owncloud\/index.php\/apps\/files\/ajax\/rename.php?dir=%2Ffolder&newname=re.txt&file=test.txt"}
    {"reqId":"E6zC8T1E4xL1Sej3uG5G","remoteAddr":"127.0.0.1","app":"PHP","message":"Call to a member function getMimetype() on boolean at \/srv\/www\/htdocs\/owncloud\/apps\/files\/lib\/helper.php#77","level":3,"time":"2015-06-12T13:44:55+00:00","method":"GET","url":"\/owncloud\/index.php\/apps\/files\/ajax\/rename.php?dir=%2Ffolder&newname=re.txt&file=test.txt"}
    

    The concurrency case happened at the time where both tried to copy the same versions.

    The expected behavior is that the folder rename is locked until the post hook is done moving the versions.

  10. PVince81 commented on Jun 12, 2015

    @PVince81
    ContributorAuthor

    Please note that post hooks are already included in the lock transaction in the code path for WebDAV PUT of small files. So if we say we still don't want to include post hooks, we'll need to change that code path to exclude them too.

    But I'd prefer if we would include them. Maybe we need to call changeLock again to SHARED.

  11. icewind1991 commented on Jun 12, 2015

    @icewind1991
    Contributor

    Ok, I'll make a PR with shared locks around post-hooks so we can properly observe the impact

  12. PVince81 commented on Jun 12, 2015

    @PVince81
    ContributorAuthor

    In theory we can already observe them with Webdav PUT of small files 😉

    Yes, please do. Thanks.

  13. PVince81 commented on Jun 12, 2015

    @PVince81
    ContributorAuthor

    You'll need to call changeLock() to convert the locks from EXCLUSIVE back to SHARED.
    Had to do it for #16900

  14. self-assigned this
    on Jun 18, 2015
  15. PVince81 commented on Jun 18, 2015

    @PVince81
    ContributorAuthor

    Ok I think I now see your point about "apps cannot modify the file in post hooks".
    On the other hand, apps that want to modify the real file in pre or post hooks should then be ported to use storage wrappers instead.

  16. PVince81 commented on Jun 18, 2015

    @PVince81
    ContributorAuthor

    PR here #17030

  17. locked as resolved and limited conversation to collaborators on Aug 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions