-
Notifications
You must be signed in to change notification settings - Fork 97
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
Prevent infinite recursion when migrating secrets to credentials while loading GitLab server configuration #450
Conversation
…e loading GitLab server configuration
src/test/java/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServersTest.java
Outdated
Show resolved
Hide resolved
src/test/java/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServersTest.java
Outdated
Show resolved
Hide resolved
// Prior to fix, this caused the GitLabServer migration code to recurse infinitely, causing problems when | ||
// starting Jenkins. | ||
// In practice this was caused by a lookup of another descriptor type, but I am using GitLabServers for | ||
// clarity. | ||
Jenkins.get().getDescriptor(GitLabServers.class); |
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 is just a minimal reproducer. In practice the real issue was with a CloudBees-specific CredentialProvider implementation which included a call to Jenkins.getDescriptor.
assertThat( | ||
logger.getMessages(), not(hasItem(containsString("Trouble loading " + GitLabServers.class.getName())))); |
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.
I wasn't sure about the best way to test the regression, but this assertion does fail if you revert the changes to src/main
, and the test log output will be full of exceptions and error messages.
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.
LGTM
I recently ran into a case where the migration code in #267 was causing an infinite loop while loading extensions during Jenkins startup, leading to various issues.
The problem is that
readResolve
on a class that is part of a@Extension PersistentDescriptor
will be called while extensions are being loaded becausePersistentDescriptor.load
is annotated with@PostConstruct
which gets called here when the extension is loaded. This means that it is not safe to do anything that requires other extensions to be loaded from withinload
and any other methods that loading may trigger. In this case the problem was the call toCredentialsProvider.lookupCredentials
inGitLabServer.readResolve
. To avoid this issue, I moved the migration to a static@Initializer
method that runs afterEXTENSIONS_AUGMENTED
, so all extensions have already been loaded at that point.Here is what the
OldDataMonitor
warning looked like, filtered to just the repeating stack frames:There was also this Guice exception in the logs:
Testing done
See new automated test.
Submitter checklist