-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Use backoff to initialize connectors in the background #3274
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>
6b30b6d
to
9a55acc
Compare
Should we maybe also parallelize connector initialization? |
Didn't invest a lot into parallelizing because for me this is the next problem. The liner code is easier to understand and to apply the backoff pattern. If you think this is worth investing more into concurrent initialization, we can:
The code then will look like this: func (s *Server) InitializeConnectors(connectors []storage.Connector) {
b := backoff.NewExponentialBackOff()
b.MaxElapsedTime = 0
b.InitialInterval = 100 * time.Millisecond
b.MaxInterval = 30 * time.Second
s.logger.Info("start initializing connectors")
for _, c := range connectors {
go func(conn storage.Connector) {
limiter := backoff.NewTicker(b)
for {
s.logger.Debugf("initializing %q connector", conn.ID)
_, err := s.OpenConnector(conn)
if err == nil {
break
}
s.logger.Error(err)
<-limiter.C // Wait for the next retry only on fails
}
s.logger.Debugf("connector %q has been initialized successfully", conn.ID)
}(c)
}
} |
563e90a
to
bac3fb3
Compare
This is required to initialize connectors faster and have a separate backoff limit. Also in this PR: * Wait for connectors initialization on test server startup * Show only initialized connector on the login page Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>
bac3fb3
to
30f1ad7
Compare
Well, if the goal is to make sure a failing connector doesn't block other connectors from initialization, then parallelization is certainly worth considering. There is another potential side effect though: Dex may start and report ready before connectors are initialized. I'm not sure if that's the case or if it's a problem, but even in your PR there is an extra goroutine now. Last, but not least: even adding a backoff may delay initialization. We might want to consider adding some sort of retry queue where failing connectors are added back at the end of the queue so we can try initializing other connectors first. In any case, this may be a more sophisticated problem that it looks at first. I'm slightly concerned about the added goroutine causing trouble on initialization. If you think this is a serious issue though and this solves it or at least serves as a temporary solution, I'm not gonna block it. Maybe hide it behind a feature flag? |
Good point, there is an additional check for the readiness probe that validates that at least one connector was initialized
In the first commit of the PR, there were a single backoff queue for all connectors, but because we decided to switch to parallel, there is now a separate queue for each connector.
Never expected it to be easy breezy 🙂
Good point, I have another PR in my pocket. Let's merge it first before introducing a new feature flag. |
Overview
This pull request introduces a crucial enhancement to the project by implementing queue-based initialization for connectors with backoff. The primary motivation behind this update is to mitigate the risk associated with misconfigured connectors, preventing a single connector from disrupting the entire functionality of the Dex.
What this PR does / why we need it
Related #2789 (there is more info)
This update significantly reduces the impact of misconfigured connectors, safeguarding the stability of the Dex by:
Special notes for your reviewer