Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-28182

Revisit use of $JENKINS_SERVER_COOKIE and Launcher.kill

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      PlaceholderExecutable needs an environment variable to add to the context to ensure that Launcher.kill, called when the block exits, will clean up any stray external processes run on this node.

      Originally the name of this variable was chosen to be JENKINS_SERVER_COOKIE, which is set by Job (to a confidential hex key) and normally used by AbstractBuild for this purpose. Unlike in that case, for Workflow the value is overridden (to a random UUID) for each node block, since there may be several. I think the intent was to use the same variable name to suppress any unwanted kills coming from Jenkins core code, but there seem to be none. Anyway after the many refactorings of environment variable handling in Workflow, it turns out this is dead code!

      • FileMonitoringTask sets its own value for JENKINS_SERVER_COOKIE, to durable-<workspaceHash>, which overrides any other value, and is used by stop. So within a shell step, $JENKINS_SERVER_COOKIE is the one from durable-task, not PlaceholderExecutable.
      • env.JENKINS_SERVER_COOKIE picks up the value from Job, due to the precedence order in getEffectiveEnvironment.

      So it seems that while the intention is still good (we would like a final check that any processes started inside node are killed when the block exits), the implementation is not right. Probably PlaceholderExecutable just needs to pick an unrelated environment variable for this purpose. And this logic needs to be tested; for example:

      def file = new File(...);
      node {
        sh "(sleep 5; touch $file) &"
      }
      sleep 10
      assert !file.exists()
      

        Attachments

          Issue Links

            Activity

            Hide
            mykola Mykola Marzhan added a comment -

            Hi all,

            sorry for reopening, I just received new jenkins update...

            Is it possible to don't reinvent variable names, but use the stable well-known approach from usual jobs?
            I am about BUILD_ID=dontKillMe variable.
            documented here https://wiki.jenkins.io/display/JENKINS/ProcessTreeKiller 

            everyone who uses jenkins a lot – know about this variable and it is extremely simple to receive info about this variable and process killing via searching.
            it is very strange and unusual to have different variables for old-school jobs and for pipelines.

             

             

            Show
            mykola Mykola Marzhan added a comment - Hi all, sorry for reopening, I just received new jenkins update... Is it possible to don't reinvent variable names, but use the stable well-known approach from usual jobs? I am about BUILD_ID=dontKillMe variable. documented here  https://wiki.jenkins.io/display/JENKINS/ProcessTreeKiller   everyone who uses jenkins a lot – know about this variable and it is extremely simple to receive info about this variable and process killing via searching. it is very strange and unusual to have different variables for old-school jobs and for pipelines.    
            Hide
            mmitche Matthew Mitchell added a comment -

            I don't think BUILD_ID was being used for killing processes before.

            Anyways, the classic approach doesn't work with pipelines.  Two executors on the same machine could run parts of the same build in parallel.  This means that when the process killer attempts to kill BUILD_ID it will kill the other executor's processes.

            We could perhaps introduce an additional environment variable, and check for both.  Thoughts Jesse Glick?

            Show
            mmitche Matthew Mitchell added a comment - I don't think BUILD_ID was being used for killing processes before. Anyways, the classic approach doesn't work with pipelines.  Two executors on the same machine could run parts of the same build in parallel.  This means that when the process killer attempts to kill BUILD_ID it will kill the other executor's processes. We could perhaps introduce an additional environment variable, and check for both.  Thoughts Jesse Glick ?
            Hide
            jglick Jesse Glick added a comment -

            Does not need to be reopened.

            I see no reason to look for BUILD_ID. As pointed out, this does not generalize well to parallel blocks.

            Show
            jglick Jesse Glick added a comment - Does not need to be reopened. I see no reason to look for BUILD_ID . As pointed out, this does not generalize well to parallel blocks.
            Hide
            mykola Mykola Marzhan added a comment -

            Hi Jesse Glick
            it is not needed to look only to BUILD_ID but it is possible to look also to BUILD_ID.
            it means kill process only in case if JENKINS_NODE_COOKIE and BUILD_ID are unchanged.

            I know that pipelines are a completely new thing, but jenkins itself is not a new thing and it very important to keep backward compatibility.
            Many people work with jenkins many years and these new variables are completely unexpected. 

            Show
            mykola Mykola Marzhan added a comment - Hi  Jesse Glick it is not needed to look only to BUILD_ID but it is possible to look also to BUILD_ID . it means kill process only in case if JENKINS_NODE_COOKIE and BUILD_ID are unchanged. I know that pipelines are a completely new thing, but jenkins itself is not a new thing and it very important to keep backward compatibility. Many people work with jenkins many years and these new variables are completely unexpected. 
            Hide
            jglick Jesse Glick added a comment -

            Could be a follow-up RFE (linked issue).

            Show
            jglick Jesse Glick added a comment - Could be a follow-up RFE (linked issue).

              People

              • Assignee:
                mmitche Matthew Mitchell
                Reporter:
                jglick Jesse Glick
              • Votes:
                1 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: