Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-5247

Pruning thread of global PowerOfTwoBufferPool causes Maven exec plugin to block

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Do
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: 4.6.0, 4.11.1
    • Component/s: Connection Management
    • None
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Summary

      try-with-resources with a classic/basic MongoClient works fine in 4.5.0 but doesn't in 4.6.0.

      In 4.5.0 I can execute my main class with a simple Maven command:

      mvn clean compile exec:java -Dexec.mainClass="com.mongodb.quickstart.transactions.Transactions" -Dmongodb.uri="mongodb://localhost"

      In 4.6.0+ I have to add "-Dexec.cleanupDaemonThreads=false" to avoid blocking for 15 seconds + java.lang.IllegalThreadStateException.

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      Reproduced with a local ephemeral single node RS in 7.0.3 using Docker.
      OK in 4.5.0.
      KO in 4.6.0 and current 4.11.1.

      How to Reproduce

      docker run --rm -d -p 27017:27017 -h $(hostname) --name mongo mongo:7.0.3 --replSet=RS && sleep 3 && docker exec mongo mongosh --quiet --eval "rs.initiate();"
      cd /tmp
      git clone git@github.com:mongodb-developer/java-quick-start.git
      cd java-quick-start
      # Change Java Driver Sync version in pom.xml depending if you want to pass or fail.
      mvn clean compile exec:java -Dexec.mainClass="com.mongodb.quickstart.Connection" -Dmongodb.uri="mongodb://localhost"

      If version >= 4.6.0 then we get:

      [WARNING] thread Thread[BufferPoolPruner-1-thread-1,5,com.mongodb.quickstart.Connection] was interrupted but is still alive after waiting at least 15000msecs
      [WARNING] thread Thread[BufferPoolPruner-1-thread-1,5,com.mongodb.quickstart.Connection] will linger despite being asked to die via interruption
      [WARNING] NOTE: 1 thread(s) did not finish despite being asked to via interruption. This is not a problem with exec:java, it is a problem with the running code. Although not serious, it should be remedied.
      [WARNING] Couldn't destroy threadgroup org.codehaus.mojo.exec.ExecJavaMojo$IsolatedThreadGroup[name=com.mongodb.quickstart.Connection,maxpri=10]
      java.lang.IllegalThreadStateException
          at java.lang.ThreadGroup.destroy (ThreadGroup.java:803)
          at org.codehaus.mojo.exec.ExecJavaMojo.execute (ExecJavaMojo.java:319)
          at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
          at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:370)
          at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:351)
          at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
          at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:171)
          at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:163)
          at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
          at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
          at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
          at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
          at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:298)
          at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
          at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
          at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
          at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
          at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
          at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
          at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
          at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke (Method.java:568)
          at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
          at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
          at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
          at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
      

      Can ignore the problem by running like this:

      mvn clean compile exec:java -Dexec.mainClass="com.mongodb.quickstart.Connection" -Dmongodb.uri="mongodb://localhost" -Dexec.cleanupDaemonThreads=false
      

       

      $ java --version 
      openjdk 17.0.9 2023-10-17
      OpenJDK Runtime Environment (build 17.0.9+9-Debian-2)
      OpenJDK 64-Bit Server VM (build 17.0.9+9-Debian-2, mixed mode, sharing)
      

       

      $ mvn --version 
      Apache Maven 3.8.7
      Maven home: /usr/share/maven
      Java version: 17.0.9, vendor: Debian, runtime: /usr/lib/jvm/java-17-openjdk-amd64
      Default locale: en, platform encoding: UTF-8
      OS name: "linux", version: "6.5.0-4-amd64", arch: "amd64", family: "unix"
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            maxime.beugnet@mongodb.com Maxime Beugnet (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: