javaswift / joss

Java library for OpenStack Storage, aka Swift
http://javaswift.org
117 stars 108 forks source link

Race condition in ContainerCache.getContainer #162

Open codeperfector opened 5 years ago

codeperfector commented 5 years ago

ContainerCache uses TreeMap which is not thread-safe.

We ran into an issue in production with calls to Account.getContainer from multiple threads. This method delegates to ContainerCache.getContainer which looks up the container by name from the internal TreeMap data structure. If there is a cache miss, it creates a new Container and puts it in the TreeMap. So you can get multiple threads concurrently accessing and modifying the TreeMap which in combination with tree rebalancing can result in some bad race conditions. We saw our threads spinning in the call to retrieve a container from the TreeMap. The solution for us was to use our own caching and disable the cache in ContainerCache. However this issue needs a permanent fix.