abashev / vfs-s3

Amazon S3 driver for Apache commons-vfs (Virtual File System) project
Apache License 2.0
93 stars 50 forks source link

fix deadlock between getChildren() and getParent() #41

Closed svella closed 7 years ago

svella commented 7 years ago

Deadlock occurs because S3FileObject uses LockByFileStrategyFactory instead of the default LockByFileSystemStrategyFactory and because getDirectory() locks the parent and then later (indirectly) locks the children one by one, whereas getParent() locks the child and then later (indirectly) locks the parent. The indirect lock comes through the resolveFile sequences that eventually get down to a place which, if the default CacheStrategy.RESOLVE is in effect, calls reset(), which calls detach(), which establishes the lock on the resolved file object .

I'm not in love with the fix, but I think it is about as clean as it is going to get using that lock strategy given how so much of the functionality of AbstractFileObject is private and therefore inaccessible to derived classes. I suspect any provider that used both LockByFileStrategyFactory (which none of the built-in providers do) and doListChildrenResolve() would run into this same issue without a similar change.

svella commented 7 years ago

Hold off on this - apparently once the children are cached, getChildren() and getParent() still can deadlock without our help because getParent() does a resolve on each of the cached children and it's not looking like there is much we can do about it other than not use LockByFileStrategyFactory or override one or both of getChildren() or getParent().

abashev commented 7 years ago

So much movements and I don't know what is going on 😬