Comments (5)
The Vault
class should be threadsafe in most common use cases. However, strictly speaking is not... and I would recommend not treating it as such, unless you're comfortable that your team would be disciplined enough to avoid the edge cases.
Vault
has only one member variable, vaultConfig
, which itself is final
. The same is true for all of the API wrapper classes that Vault
returns (e.g. Logical
, Debug
, etc.).
However, being final
in Java does NOT mean immutable! You could still have multiple threads making changes to this config object's internals concurrently, and that would cause problems for sure.
The VaultConfig
class uses the builder pattern, specifically to discourage mutating an instance after it's initially built. However, people COULD do it if they wanted to.
More importantly, Vault
itself mutates its config when you call withRetries(...)
. This would probably be the biggest risk, because I could see users applying different retry settings to different API calls.
So.... IF you are not mutating your VaultConfig
objects after building them, and IF you are not calling Vault.withRetries(...)
from different places in your code with different values... then you are probably threadsafe in practice. However, we instantiate a new Vault
for every thread, and that's the pattern I would recommend.
If there's demand for making Vault
threadsafe, then we might look at modifying its internals with locks to prevent concurrent modification. However, my hunch is that the overhead of managing the locks would hurt performance more than the overhead of object creation (I could be wrong).
from vault-java-driver.
@steve-perkins thanks for responding. The above usage pattern sound reasonable, VaultConfig
instance mutation should be handled only during client setup.
As for the withRetries
aspect - well, it sounds like a common use pattern and having that be thread-unsafe is not that good. There might be some other way around it with synchronization/object recreation, but that'll require some refactoring. Would you be open to that ?
from vault-java-driver.
Sure! If you have any design proposals or want to try putting together a PR, I'd love to go over it. It may be a week or before I could get to it personally.
The solution may be as simple as adding synchronized
to all of the VaultConfig
builder methods (or at least the setMaxRetries(...)
and setRetryIntervalMilliseconds(...)
mutators that are called by Vault.withRetries(...)
).
It just worries me that these VaultConfig
objects are passed by Vault
to all of the API wrappers, and stored there too. Then again, I suppose it's the same object reference shared by all them...
from vault-java-driver.
@steve-perkins Has your answer on this changed since you made it? Are there any other potential edge-conditions in using this between threads?
Depending on your answer, I could potentially open a PR to make it fully thread safe, or open a PR to document any concurrency considerations.
Thanks in advance! This looks like a great client.
from vault-java-driver.
Thanks, @NathanC. I'm certainly OPEN to the idea of making it possible and safe to swap out a Vault
instance's VaultConfig
object after instantiation... even if I'd probably never do so in my own code.
Either way, I would be extremely appreciative of any investigation or documentation around other concurrency considerations in general. I personally just don't share Vault
instances between threads, so it hasn't been an issue for me or my company. In my original answer above, when I said that I don't think there are any considerations beyond the VaultConfig
instance, that was an educated guess without any real legwork behind it.
from vault-java-driver.
Related Issues (20)
- How to access data stored in Dyanmic Database
- Clarification on prefixPath HOT 1
- externalize integration test set up as seperate module
- Vault transit fails when engineVersion set to 2
- clarify relationship between http api path and read path HOT 1
- Using Transit service doesn't work for anything other than engine Version 1
- Authentication using certificate: curl working, but java driver is having issues HOT 1
- parseResponseData crashes and returns empty object (for 5.1.0)
- SSL connection reusage HOT 2
- NPE thrown when sslConfig not set.
- Can't get the resource for my .pem certificate HOT 1
- Question: Need documentation : How to use loginByGCP(), How to generate JWT token? HOT 1
- missing option exclude_cn_from_sans when requesting a signed certificate
- Better SSL configuration
- Support for non-blocking HTTP requests
- Is project dead? HOT 1
- Unable to use Logical read API
- Caused by: java.lang.NullPointerException: null at com.bettercloud.vault.rest.Rest.responseBodyBytes(Rest.java:519)
- Unable to retrieve config data from HC Vault in Scala
- clientKeyPemUTF8() doesn't support -----BEGIN RSA PRIVATE KEY----- header
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vault-java-driver.