[JIRA] (JENKINS-37759) Usage of @Initializer(after = InitMilestone.COMPLETED) in plugins breaks the initialization logic

20 views
Skip to first unread message

o.v.nenashev@gmail.com (JIRA)

unread,
Aug 30, 2016, 5:56:05 AM8/30/16
to jenkinsc...@googlegroups.com
Oleg Nenashev updated an issue
 
Jenkins / Bug JENKINS-37759
Usage of @Initializer(after = InitMilestone.COMPLETED) in plugins breaks the initialization logic
Change By: Oleg Nenashev
Summary: After startup Usage of the instance with many jobs1, the setup does not end up @Initializer(after = InitMilestone.COMPLETED) in plugins breaks the COMPLETED milestone initialization logic
Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.1.7#71011-sha1:2526d7c)
Atlassian logo

o.v.nenashev@gmail.com (JIRA)

unread,
Aug 30, 2016, 6:01:01 AM8/30/16
to jenkinsc...@googlegroups.com
Oleg Nenashev updated an issue
It happens due to https://github.com/jenkinsci/jenkins/pull/2177/files, which makes COMPLETED dependent on

The problem is in
the following logic Initializer code :


{code}
            /
/ All plugins are loaded **
     * Indicates that the specified milestone is necessary before executing this initializer
. Now we can figure out who depends on who.
     *
     * <p>
     * This has the identical purpose as {@link #
             requires( PLUGINS_PREPARED ) .attains }, but it's separated to allow better type-safety
     * when using {@link InitMilestone} as a requirement
( COMPLETED) since enum member definitions need to be constant . add )
     */
    InitMilestone after
( "Resolving Dependant Plugins Graph", new Executable( ) { default STARTED;
                 @Override
                 public void run     /**
     * Indicates that this initializer is a necessary step before achieving the specified milestone.
     *
     * <p>
     * This has the identical purpose as {@link #attains
( Reactor reactor ) throws Exception }. See {
                     resolveDependantPlugins
@link #after () ;
                 } for why there are two things
             }      * to achieve the same goal.
     */
    InitMilestone before(
) default COMPLETED ;
{code}

In this case If an initializer overrides <code>after</code> as COMPLETED state logic does not depend on the Job loading state , hence COMPLETED milestone can be achieved before JOB_LOADED we end up in the reactor. It may easily happen situation when Job loading takes MUCH time (<code>before == after == COMPLETED</code>) . In such case COMPLETED state gets overridden by JOB_LOADED Jenkins' reactor can never succeed in the canRun() check, and finally we do not invoke "Initialization completed" milestone since the code requires the dependency to be executed . So we get into chicken-and-egg

Sample script for the issue analysis:
{code}
import hudson.init.InitMilestone;
import hudson.util.HttpResponses;
import javax.servlet.http.HttpServletResponse;

final Jenkins jenkins = Jenkins.getInstance();

if (jenkins.getInitLevel().compareTo(InitMilestone.COMPLETED) < 0) {
  println "Error: Jenkins initialization has not reached the COMPLETED state. Current state is ${jenkins.getInitLevel()}"
  return HttpResponses.status(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
}
{code}


Examples:
* https://github.com/jenkinsci/extreme-notification-plugin/blob/0249acced3d5483841e06849a4481c47a7e28fe5/src/main/java/org/jenkinsci/plugins/extremenotification/ServerStateListener.java#L51 (JENKINS-37780)
* https://github.com/jenkinsci/support-core-plugin/blob/3cc53c1af1d2332bf5c6396987fe1516880b81a8/src/main/java/com/cloudbees/jenkins/support/SupportPlugin.java#L409 (JENKINS-37772)

Proposed changes:
* Add injected test, which verifies the startup InitMilestone of Jenkins
* Make Jenkins robust against wrong definitions
* Finally add support of Initializers after COMPLETED by introducing a transient milestone

o.v.nenashev@gmail.com (JIRA)

unread,
Aug 30, 2016, 6:12:02 AM8/30/16
to jenkinsc...@googlegroups.com

o.v.nenashev@gmail.com (JIRA)

unread,
Aug 30, 2016, 6:12:02 AM8/30/16
to jenkinsc...@googlegroups.com

o.v.nenashev@gmail.com (JIRA)

unread,
Aug 30, 2016, 6:12:02 AM8/30/16
to jenkinsc...@googlegroups.com

o.v.nenashev@gmail.com (JIRA)

unread,
Aug 30, 2016, 6:47:03 AM8/30/16
to jenkinsc...@googlegroups.com
Oleg Nenashev started work on Bug JENKINS-37759
 
Change By: Oleg Nenashev
Status: Open In Progress

o.v.nenashev@gmail.com (JIRA)

unread,
Aug 30, 2016, 6:47:03 AM8/30/16
to jenkinsc...@googlegroups.com

o.v.nenashev@gmail.com (JIRA)

unread,
Aug 30, 2016, 6:47:03 AM8/30/16
to jenkinsc...@googlegroups.com

scm_issue_link@java.net (JIRA)

unread,
Aug 30, 2016, 6:13:02 PM8/30/16
to jenkinsc...@googlegroups.com

Code changed in jenkins
User: Oleg Nenashev
Path:
src/main/java/org/jenkinsci/plugins/extremenotification/MyItemListener.java
src/main/java/org/jenkinsci/plugins/extremenotification/ServerStateListener.java
src/test/java/org/jenkinsci/plugins/extremenotification/PluginInitializationTest.java
http://jenkins-ci.org/commit/extreme-notification-plugin/1814673042bb450de5ec5401bf8096abccc5ff67
Log:
[FIXED JENKINS-37780] - The code should not use Initializer(after=InitMilestone.COMPLETED) due to JENKINS-37759

o.v.nenashev@gmail.com (JIRA)

unread,
Dec 20, 2016, 2:21:01 PM12/20/16
to jenkinsc...@googlegroups.com
Oleg Nenashev resolved as Fixed
 

The fix has not been released by the maintainer yet, but I think my work is done here

Change By: Oleg Nenashev
Status: In Progress Resolved
Resolution: Fixed
Reply all
Reply to author
Forward
0 new messages