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

Use setsid instead of nohup

    XMLWordPrintable

Details

    • durable-task 1.31

    Description

      durable task step currently uses nohup to launch a durable process. But if Jenkins is started from an interactive terminal and the user presses Ctrl+C, the forked process is still gone. So far we've blushed it off saying this is not how Jenkins is typically run. That may be true, but it is also a perfectly reasonable way to run Jenkins, for example for the first time evaluation.

      The reason these processes get killed with Ctrl+C is because shell sends SIGINT to all the processes in the process group (source). In looking at nohup.c, nohup only ignores SIGHUP. You can also run a command like nohup sleep 30 from the command line. hit Ctrl+C, and observe that the sleep 30 process gets killed.

      The root problem is that nohup is a poor way to isolate a child process. Specifically, it doesn't put the process into a new process group, so it's vulnerable to any signal sent to the entire process group (of which Ctrl+C is one.) setsid is a better way of doing this. This puts the process into a new session (hence also new process group.) So no group-wide signal will get to the child process.

      See Wikipedia process group page for interaction of signals, process groups, and sessions.

      Attachments

        Issue Links

          Activity

            kohsuke Kohsuke Kawaguchi created issue -
            kohsuke Kohsuke Kawaguchi made changes -
            Field Original Value New Value
            Priority Minor [ 4 ] Major [ 3 ]
            kohsuke Kohsuke Kawaguchi made changes -
            Description durable task step currently uses {{nohup}} to launch a durable process. But if Jenkins is started from an interactive terminal and the user presses {{Ctrl+C}}, the forked process is still gone. So far we've blushed it off saying this is not how Jenkins is typically run. That may be true, but it is also a perfectly reasonable way to run Jenkins, for example for the first time evaluation.

            The reason these processes get killed with {{Ctrl+C}} is because shell sends {{SIGINT}} to all the processes in the process group ([source|http://superuser.com/questions/708919/ctrlc-in-a-sub-process-is-killing-a-nohuped-process-earlier-in-the-script]). In looking at {{nohup.c}}, nohup [only ignores SIGHUP|https://gist.github.com/kohsuke/0eeb9bb43ca8d62643dd#file-nohup-c-L219]. You can also run a command like {{nohup sleep 30}} from the command line. hit {{Ctrl+C}}, and observe that the {{sleep 30}} process gets killed.

            The root problem is that {{nohup}} is a poor way to isolate a child process. Specifically, it doesn't put the process into a new process group, so it's vulnerable to any signal sent to the entire process group (of which {{Ctrl+C}} is one.) {{setsid}} is a better way of doing this. This puts the process into a new session (hence also new process group.) So no group-wide signal will get to the child process.

            See [Wikipedia process group page|http://en.wikipedia.org/wiki/Process_group] for interaction of signals, process groups, and sessions.
            durable task step currently uses {{nohup}} to launch a durable process. But if Jenkins is started from an interactive terminal and the user presses {{Ctrl+C}}, the forked process is still gone. So far we've blushed it off saying this is not how Jenkins is typically run. That may be true, but it is also a perfectly reasonable way to run Jenkins, for example for the first time evaluation.

            The reason these processes get killed with {{Ctrl+C}} is because shell sends {{SIGINT}} to all the processes in the process group ([source|http://superuser.com/questions/708919/ctrlc-in-a-sub-process-is-killing-a-nohuped-process-earlier-in-the-script]). In looking at {{nohup.c}}, nohup [only ignores SIGHUP|https://gist.github.com/kohsuke/0eeb9bb43ca8d62643dd#file-nohup-c-L219]. You can also run a command like {{nohup sleep 30}} from the command line. hit {{Ctrl+C}}, and observe that the {{sleep 30}} process gets killed.

            The root problem is that {{nohup}} is a poor way to isolate a child process. Specifically, it doesn't put the process into a new process group, so it's vulnerable to any signal sent to the entire process group (of which {{Ctrl+C}} is one.) {{[setsid|https://gist.github.com/kohsuke/2ed6558d3c4d1f129837]}} is a better way of doing this. This puts the process into a new session (hence also new process group.) So no group-wide signal will get to the child process.

            See [Wikipedia process group page|http://en.wikipedia.org/wiki/Process_group] for interaction of signals, process groups, and sessions.
            jglick Jesse Glick made changes -
            Labels workflow
            integer Kanstantsin Shautsou made changes -
            Link This issue is related to JENKINS-25848 [ JENKINS-25848 ]
            ydubreuil Yoann Dubreuil made changes -
            Link This issue is related to JENKINS-27617 [ JENKINS-27617 ]
            jglick Jesse Glick made changes -
            Epic Link JENKINS-35399 [ 171192 ]
            rtyler R. Tyler Croy made changes -
            Workflow JNJira [ 159471 ] JNJira + In-Review [ 179993 ]
            abayer Andrew Bayer made changes -
            Labels workflow pipeline workflow
            abayer Andrew Bayer made changes -
            Labels pipeline workflow pipeline
            jglick Jesse Glick made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            jglick Jesse Glick made changes -
            Status In Progress [ 3 ] Open [ 1 ]
            jglick Jesse Glick made changes -
            Attachment JENKINS-25503-setsid.diff [ 40193 ]
            jglick Jesse Glick made changes -
            Link This issue relates to JENKINS-47791 [ JENKINS-47791 ]
            cloudbees CloudBees Inc. made changes -
            Remote Link This issue links to "CloudBees Internal CJP-1956 (Web Link)" [ 19017 ]
            vivek Vivek Pandey made changes -
            Labels pipeline pipeline triaged-2018-11
            jglick Jesse Glick made changes -
            Link This issue relates to JENKINS-58290 [ JENKINS-58290 ]
            jglick Jesse Glick made changes -
            Assignee Jesse Glick [ jglick ]
            jglick Jesse Glick made changes -
            Remote Link This issue links to "durable-task #106 (Web Link)" [ 23610 ]
            jglick Jesse Glick made changes -
            Assignee Carroll Chiou [ carroll ]
            jglick Jesse Glick made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            jglick Jesse Glick made changes -
            Status In Progress [ 3 ] In Review [ 10005 ]
            jglick Jesse Glick made changes -
            Link This issue relates to JENKINS-50379 [ JENKINS-50379 ]
            carroll Carroll Chiou made changes -
            Released As durable-task 1.31
            Resolution Fixed [ 1 ]
            Status In Review [ 10005 ] Fixed but Unreleased [ 10203 ]
            carroll Carroll Chiou made changes -
            Status Fixed but Unreleased [ 10203 ] Resolved [ 5 ]
            jglick Jesse Glick made changes -
            Link This issue relates to JENKINS-25053 [ JENKINS-25053 ]

            People

              carroll Carroll Chiou
              kohsuke Kohsuke Kawaguchi
              Votes:
              1 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: