-
Notifications
You must be signed in to change notification settings - Fork 5
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
client/setec: single-flight dynamic lookups #98
Conversation
For callers like scertec, it is very likely that a dynamic lookup may have a large number of goroutines that all want the same secrets near a (re)start. Single-flight the lookup so they don't all pound the secrets service and then race on poking the value into the store.
e1ff3d1
to
3c405ce
Compare
client/setec/store.go
Outdated
} else if !errors.Is(err, context.DeadlineExceeded) && !errors.Is(err, context.Canceled) { | ||
return nil, err | ||
} | ||
// Cancelled or deadline exceeed. If it was us, we'll fall off the loop. | ||
} | ||
s.logf("[store] added new undeclared secret %q", name) | ||
return s.secretLocked(name), nil | ||
return nil, ctx.Err() |
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.
You don't return the best error here in the case of the non-coalesced caller hitting its timeout: rather than seeing a net/http Client Do timeout with a certain URL wrapping a timeout error, you'll instead just get a timeout.
On line 384 maybe add an || ctx.Err() != nil around the whole thing? Or look at the Result.Shared value?
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.
That makes sense to me. I found the formulation a little tricky with the negations as they were, so I reworked it a bit, see what you think.
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.
Great, thanks!
From a discussion with @bradfitz. We already have single-flighting in the
store for polls anyway, so this is a straightforward extension.
For callers like scertec, it is very likely that a dynamic lookup may have a
large number of goroutines that all want the same secrets near a (re)start.
Single-flight the lookup so they don't all pound the secrets service and then
race on poking the value into the store.