Consul is a distributed, highly available, and data center aware solution to connect and configure applications across dynamic, distributed infrastructure.
When not using the agent cache, RPC responses returned can be considered "owned" by the caller. The data can be modified or filtered as necessary. However when the agent cache is in use the data cannot be modified as its being held onto by the cache itself and other code could be using it. In the best case that would result in incorrect data but in the worst it would result in consul crashing.
Suggested Fix
I think it would be okay to have the cache copy the cached RPC responses before returning them. It would be a little overhead but seems worth it in order to provide similar semantics to doing the regular RPC request.
@mkeeler yes, that's exactly what I suggested to @Aestek, but he chose to deal with it outside of cache to ease review, but I think you are right, copy should be returned
Overview of the Issue
When not using the agent cache, RPC responses returned can be considered "owned" by the caller. The data can be modified or filtered as necessary. However when the agent cache is in use the data cannot be modified as its being held onto by the cache itself and other code could be using it. In the best case that would result in incorrect data but in the worst it would result in consul crashing.
Suggested Fix
I think it would be okay to have the cache copy the cached RPC responses before returning them. It would be a little overhead but seems worth it in order to provide similar semantics to doing the regular RPC request.
This other PR is one example of a bug that can crop up because of the issue: https://github.com/hashicorp/consul/pull/5398