Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
agent: add an inflight cache better concurrent request handling #10705
agent: add an inflight cache better concurrent request handling #10705
Changes from 19 commits
efb17f1
5adbf7f
01d3094
ade1b13
e434bab
512e426
8eab0f3
63e0734
12b9cb3
fcc5ccf
a407d7f
a2cafc1
47383ea
474cfc2
06d0f22
20eb35b
ea4d6c8
8d1641e
6fed851
3b51125
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When would
inflight
benil
at this point?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't be nil because the conditional further down always assigns this values to something, but I'm nil-checking just in case since this is within a defer that's called right after the variable is declared but before the value is assigned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This felt a little racy since we can be here multiple times for the same id if a request comes in right after the condition
Load() == 0
is checked. But I've gone through it and don't think there is any harmful behavior. Theinflight
object still exists even if it's deleted from the cache so the final request can complete, and callingDelete()
on an id not present is a no-op.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So right now if we detect here that the thread processing the request has completed (channel has been closed) then we simply continue. But once we get down to:
We'd see an nil cachedResp since that is still going to only cache leased values. Then, i think, we'd simply re-send the request to the Vault server. I think this fix is missing a step where we store the resulting request in the
inflightRequest
object and access it here when the channel is closed. Thoughts?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The winner who had closed the channel will have cached the response before this thread gets to call
c.checkCacheForRequest(id)
so it will result in a cache hit. In the case that the request resulted in a non-cacheable response, it would proxy to Vault as it should.The changes in the PR don't actually prevent identical non-cacheable requests from being proxied to Vault; it simply allows one of the requests to be processed first (since we don't know if it's cacheable) before opening the floodgate to let other identical request to be processed concurrently. I don't think there's a need to store the actual request/response object in the
inflightRequest
.