-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RESTDataSource should not cache requests to the same URL for different Authorization header values #4486
Comments
As is now better explained (after #5086), you shouldn't share data source objects across requests. Given that, I don't think the suggested change about |
Hi @glasser, Thanks for following this up. FWIW, I still think the default behaviour can be dangerous and I don't think updating the docs necessarily solves the problem. This feels like putting a warning in the user manual of a saw; just put a guard on it so no one loses a finger. |
I have to agree with @mcilvena - ran into a couple of issues that took away a bunch of time only to realise that the RESTDataSource memoises responses based on the url :( Idk why, but I had imagined a more elegant way of creating cache keys |
Package:
apollo-datasource-rest
Version:
0.9.0
TL;DR:
RESTDataSource
's default behaviour of using just the request URL as the cache key is dangerous in cases where a single instance of DataSource is used to make multiple request with differingAuthorization
headers to upstream services.Background context:
The company I work for recently experienced a pretty serious production issue as a result of a code refactor that moved a datasource instantiation from inside
ApolloServer
'sdataSources
constructor property to and external file.Example.
Before:
After (defect introduced):
Actual Behaviour:
As a result of initialising the datasource outside of the
dataSources
factory function, each application instance can accept requests for multiple authorized users, reusing the same internal cache (keyed on upstream URL) ofRESTDataSource
. This results in data of initial request's user being returned to all subsequent users (this is obviously very bad).Expected behaviour:
Whether new to
ApolloServer
or not, I've seem mutliple developers trip on this implicit requirement for datasources to be instantiated insideConfig
sdataSources
function. This requirement and its potential consequences are not obvious or intuitive enough.I would expect consistent behaviour regardless or where the datasource is instantiated. Maybe the cache should be reinitialised on each request as part of the
requestPipeline
; or default to separating the cache for differentAuthorization
header values.The text was updated successfully, but these errors were encountered: