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

JenkinsRule: Jetty leaves stray threads running after server.stop()

    Details

    • Similar Issues:

      Description

       
      I was debugging through JenkinsRule from Jenkins Test Harness. After the Jetty server and Jenkins have both been terminated in JenkinsRule#after() (line 488 and line 502, respectively) stray threads keep running. Attached is the dump of the running threads. Is it possible to terminate these threads to allow the JVM to exit gracefully?
       
      This issue may already have been reported before in this Stack Overflow question: https://stackoverflow.com/questions/13769007/jetty-server-leaves-behind-threads-after-stop
       
      A minimal example would be following test code and setting a breakpoint at the System.gc() call on line 517:
       

      import org.junit.Rule;
      import org.junit.Test;
      import org.jvnet.hudson.test.JenkinsRule;
      
      public class RandomTest {
          @Rule
          public JenkinsRule jenkinsRule = new JenkinsRule();
      
          @Test
          public void randomTest() {
              System.out.println("Hello world");
          }
      }
      

       
      I was able to confirm the behaviour with the latest Jetty on both Windows 10 and Linux.
       
      This issues was discussed on the developer mailing list: https://groups.google.com/forum/#!topic/jenkinsci-dev/7yL0MKjxQwA

        Attachments

          Activity

          Hide
          jglick Jesse Glick added a comment -

          Is there a concrete problem this behavior is causing? mvn test failures, etc.?

          Show
          jglick Jesse Glick added a comment - Is there a concrete problem this behavior is causing? mvn test failures, etc.?
          Hide
          olamy Olivier Lamy added a comment -

          can you please provide a project with a pom. To know which version you are using.

          And yes last but not least what is the real problem?

           

          Show
          olamy Olivier Lamy added a comment - can you please provide a project with a pom. To know which version you are using. And yes last but not least what is the real problem?  
          Hide
          abhyudaya Abhyudaya Sharma added a comment - - edited

          Hi. I'm working creating a framework to benchmark Jenkins using Java Microbenchmark Harness. To do that, I'm starting a Jenkins instance similar to how it is done by JenkinsRule. When the instance  is terminated (after the benchmark has completed) using server.stop() and Jenkins.cleanup(), these threads keep running and cause JMH to wait and later forcefully kill the JVM.

          This has been implemented in Role Strategy Plugin so the pom is: https://github.com/jenkinsci/role-strategy-plugin/blob/master/pom.xml

          However, I did manually update all of the Jetty dependencies to the latest version and I was able to observe it again:

           

          1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
                <modelVersion>4.0.0</modelVersion>
            
                <parent>
                    <groupId>org.jenkins-ci.plugins</groupId>
                    <artifactId>plugin</artifactId>
                    <version>3.43</version>
                </parent>
            
                <artifactId>role-strategy</artifactId>
                <packaging>hpi</packaging>
                <version>${revision}${changelist}</version>
                <name>Role-based Authorization Strategy</name>
                <url>https://wiki.jenkins.io/display/JENKINS/Role+Strategy+Plugin</url>
            
                <scm>
                    <connection>scm:git:ssh://github.com/jenkinsci/${project.artifactId}-plugin.git</connection>
                    <developerConnection>scm:git:ssh://git@github.com/jenkinsci/${project.artifactId}-plugin.git</developerConnection>
                    <url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
                  <tag>${scmTag}</tag>
              </scm>
            
                <developers>
                    <developer>
                        <id>tmaurel</id>
                        <name>Thomas Maurel</name>
                        <timezone>+1</timezone>
                    </developer>
                    <developer>
                        <id>rseguy</id>
                        <name>Romain Seguy</name>
                        <timezone>+1</timezone>
                    </developer>
                    <developer>
                        <name>Oleg Nenashev</name>
                        <id>oleg_nenashev</id>
                        <email>o.v.nenashev@gmail.com</email>
                    </developer>
                </developers>
            
                <properties>
                    <revision>2.12</revision>
                    <changelist>-SNAPSHOT</changelist>
                    <jenkins.version>2.60.3</jenkins.version>
                    <java.level>8</java.level>
                    <configuration-as-code.version>1.17</configuration-as-code.version>
                </properties>
            
                <repositories>
                    <repository>
                        <id>repo.jenkins-ci.org</id>
                        <url>https://repo.jenkins-ci.org/public/</url>
                    </repository>
                </repositories>
            
                <pluginRepositories>
                    <pluginRepository>
                        <id>repo.jenkins-ci.org</id>
                        <url>https://repo.jenkins-ci.org/public/</url>
                    </pluginRepository>
                </pluginRepositories>
            
                <licenses>
                    <license>
                        <name>MIT License</name>
                        <url>https://www.opensource.org/licenses/mit-license.php</url>
                        <distribution>repo</distribution>
                    </license>
                </licenses>
            
                <dependencies>
                    <dependency>
                        <groupId>org.jenkins-ci.plugins</groupId>
                        <artifactId>matrix-auth</artifactId>
                        <version>2.2</version>
                    </dependency>
                    <dependency>
                        <groupId>org.hamcrest</groupId>
                        <artifactId>hamcrest-junit</artifactId>
                        <version>2.0.0.0</version>
                        <scope>test</scope>
                    </dependency>
                    <dependency>
                        <groupId>org.jenkins-ci.plugins</groupId>
                        <artifactId>cloudbees-folder</artifactId>
                        <version>6.1.0</version>
                        <scope>test</scope>
                    </dependency>
                    <dependency>
                        <groupId>org.jenkins-ci.plugins</groupId>
                        <artifactId>jquery</artifactId>
                        <version>1.11.2-0</version>
                    </dependency>
                    <dependency>
                        <groupId>org.jenkins-ci.plugins</groupId>
                        <artifactId>jquery-ui</artifactId>
                        <version>1.0.1</version>
                    </dependency>
                    <dependency>
                        <groupId>org.openjdk.jmh</groupId>
                        <artifactId>jmh-core</artifactId>
                        <version>1.21</version>
                        <scope>test</scope>
                    </dependency>
                    <dependency>
                        <groupId>org.openjdk.jmh</groupId>
                        <artifactId>jmh-generator-annprocess</artifactId>
                        <version>1.21</version>
                        <scope>test</scope>
                    </dependency>
                    <dependency>
                        <groupId>io.jenkins</groupId>
                        <artifactId>configuration-as-code</artifactId>
                        <version>${configuration-as-code.version}</version>
                        <optional>true</optional>
                    </dependency>
                    <dependency>
                        <groupId>io.jenkins</groupId>
                        <artifactId>configuration-as-code</artifactId>
                        <version>${configuration-as-code.version}</version>
                        <classifier>tests</classifier>
                        <scope>test</scope>
                    </dependency>
                    <dependency>
                        <groupId>org.reflections</groupId>
                        <artifactId>reflections</artifactId>
                        <version>0.9.11</version>
                        <scope>test</scope>
                    </dependency>
                    <dependency>
                        <groupId>org.eclipse.jetty.websocket</groupId>
                        <artifactId>websocket-api</artifactId>
                        <version>9.4.18.v20190429</version>
                    </dependency>
                    <dependency>
                        <groupId>org.eclipse.jetty.websocket</groupId>
                        <artifactId>websocket-client</artifactId>
                        <version>9.4.18.v20190429</version>
                    </dependency>
                    <dependency>
                        <groupId>org.eclipse.jetty</groupId>
                        <artifactId>jetty-server</artifactId>
                        <version>9.4.18.v20190429</version>
                    </dependency>
                    <dependency>
                        <groupId>org.eclipse.jetty</groupId>
                        <artifactId>jetty-servlet</artifactId>
                        <version>9.4.18.v20190429</version>
                    </dependency>
                    <dependency>
                        <groupId>org.eclipse.jetty</groupId>
                        <artifactId>jetty-security</artifactId>
                        <version>9.4.18.v20190429</version>
                    </dependency>
                    <dependency>
                        <groupId>org.eclipse.jetty</groupId>
                        <artifactId>jetty-webapp</artifactId>
                        <version>9.4.18.v20190429</version>
                    </dependency>
                </dependencies>
            
                <profiles>
                    <!-- Profile to run benchmarks when the `benchmark` property is set -->
                    <profile>
                        <id>jmh-benchmark</id>
                        <activation>
                            <property>
                                <name>benchmark</name>
                            </property>
                        </activation>
                        <build>
                            <plugins>
                                <plugin>
                                    <groupId>org.apache.maven.plugins</groupId>
                                    <artifactId>maven-surefire-plugin</artifactId>
                                    <configuration>
                                        <includes>
                                            <include>**/*Benchmark.java</include>
                                            <include>**/Benchmark*.java</include>
                                        </includes>
                                    </configuration>
                                </plugin>
                            </plugins>
                        </build>
                    </profile>
                </profiles>
            </project>
            
            

           

           

          Show
          abhyudaya Abhyudaya Sharma added a comment - - edited Hi. I'm working creating a framework to benchmark Jenkins using Java Microbenchmark Harness. To do that, I'm starting a Jenkins instance similar to how it is done by JenkinsRule. When the instance  is terminated (after the benchmark has completed) using server.stop() and Jenkins.cleanup(), these threads keep running and cause JMH to wait and later forcefully kill the JVM. This has been implemented in Role Strategy Plugin so the pom is:  https://github.com/jenkinsci/role-strategy-plugin/blob/master/pom.xml However, I did manually update all of the Jetty dependencies to the latest version and I was able to observe it again:   <project xmlns= "http: //maven.apache.org/POM/4.0.0" xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" > <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.jenkins-ci.plugins</groupId> <artifactId>plugin</artifactId> <version>3.43</version> </parent> <artifactId>role-strategy</artifactId> <packaging>hpi</packaging> <version>${revision}${changelist}</version> <name>Role-based Authorization Strategy</name> <url>https: //wiki.jenkins.io/display/JENKINS/Role+Strategy+Plugin</url> <scm> <connection>scm:git:ssh: //github.com/jenkinsci/${project.artifactId}-plugin.git</connection> <developerConnection>scm:git:ssh: //git@github.com/jenkinsci/${project.artifactId}-plugin.git</developerConnection> <url>https: //github.com/jenkinsci/${project.artifactId}-plugin</url> <tag>${scmTag}</tag> </scm> <developers> <developer> <id>tmaurel</id> <name>Thomas Maurel</name> <timezone>+1</timezone> </developer> <developer> <id>rseguy</id> <name>Romain Seguy</name> <timezone>+1</timezone> </developer> <developer> <name>Oleg Nenashev</name> <id>oleg_nenashev</id> <email>o.v.nenashev@gmail.com</email> </developer> </developers> <properties> <revision>2.12</revision> <changelist>-SNAPSHOT</changelist> <jenkins.version>2.60.3</jenkins.version> <java.level>8</java.level> <configuration-as-code.version>1.17</configuration-as-code.version> </properties> <repositories> <repository> <id>repo.jenkins-ci.org</id> <url>https: //repo.jenkins-ci.org/ public /</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>repo.jenkins-ci.org</id> <url>https: //repo.jenkins-ci.org/ public /</url> </pluginRepository> </pluginRepositories> <licenses> <license> <name>MIT License</name> <url>https: //www.opensource.org/licenses/mit-license.php</url> <distribution>repo</distribution> </license> </licenses> <dependencies> <dependency> <groupId>org.jenkins-ci.plugins</groupId> <artifactId>matrix-auth</artifactId> <version>2.2</version> </dependency> <dependency> <groupId>org.hamcrest</groupId> <artifactId>hamcrest-junit</artifactId> <version>2.0.0.0</version> <scope>test</scope> </dependency> <dependency> <groupId>org.jenkins-ci.plugins</groupId> <artifactId>cloudbees-folder</artifactId> <version>6.1.0</version> <scope>test</scope> </dependency> <dependency> <groupId>org.jenkins-ci.plugins</groupId> <artifactId>jquery</artifactId> <version>1.11.2-0</version> </dependency> <dependency> <groupId>org.jenkins-ci.plugins</groupId> <artifactId>jquery-ui</artifactId> <version>1.0.1</version> </dependency> <dependency> <groupId>org.openjdk.jmh</groupId> <artifactId>jmh-core</artifactId> <version>1.21</version> <scope>test</scope> </dependency> <dependency> <groupId>org.openjdk.jmh</groupId> <artifactId>jmh-generator-annprocess</artifactId> <version>1.21</version> <scope>test</scope> </dependency> <dependency> <groupId>io.jenkins</groupId> <artifactId>configuration-as-code</artifactId> <version>${configuration-as-code.version}</version> <optional> true </optional> </dependency> <dependency> <groupId>io.jenkins</groupId> <artifactId>configuration-as-code</artifactId> <version>${configuration-as-code.version}</version> <classifier>tests</classifier> <scope>test</scope> </dependency> <dependency> <groupId>org.reflections</groupId> <artifactId>reflections</artifactId> <version>0.9.11</version> <scope>test</scope> </dependency> <dependency> <groupId>org.eclipse.jetty.websocket</groupId> <artifactId>websocket-api</artifactId> <version>9.4.18.v20190429</version> </dependency> <dependency> <groupId>org.eclipse.jetty.websocket</groupId> <artifactId>websocket-client</artifactId> <version>9.4.18.v20190429</version> </dependency> <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-server</artifactId> <version>9.4.18.v20190429</version> </dependency> <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-servlet</artifactId> <version>9.4.18.v20190429</version> </dependency> <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-security</artifactId> <version>9.4.18.v20190429</version> </dependency> <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-webapp</artifactId> <version>9.4.18.v20190429</version> </dependency> </dependencies> <profiles> <!-- Profile to run benchmarks when the `benchmark` property is set --> <profile> <id>jmh-benchmark</id> <activation> <property> <name>benchmark</name> </property> </activation> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <includes> <include>**/*Benchmark.java</include> <include>**/Benchmark*.java</include> </includes> </configuration> </plugin> </plugins> </build> </profile> </profiles> </project>    

            People

            • Assignee:
              olivergondza Oliver Gondža
              Reporter:
              abhyudaya Abhyudaya Sharma
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: