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

RejectedExecutionException happens in driver

    • Fully Compatible
    • Not Needed

      During my integration tests, I setup a 3-node replica-set in docker, and connect to it with Java client. 

      Often I get this exception in the logs:

      Exception in thread "cluster-ClusterId{value='62415548404dc25237ffe99d', description='null'}-127.0.0.1:55059" Exception in thread "cluster-ClusterId{value='62415548404dc25237ffe99d', description='null'}-127.0.0.1:55058" java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@39dcce0f[Not completed, task = java.util.concurrent.Executors$RunnableAdapter@3324a57f[Wrapped task = com.mongodb.internal.connection.DefaultConnectionPool$BackgroundMaintenanceManager$$Lambda$194/0x00000008003b9440@3de34d6b]] rejected from java.util.concurrent.ScheduledThreadPoolExecutor@7cde4750[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]
      	at java.base/java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2055)
      	at java.base/java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:825)
      	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:340)
      	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor.scheduleAtFixedRate(ScheduledThreadPoolExecutor.java:632)
      	at java.base/java.util.concurrent.Executors$DelegatedScheduledExecutorService.scheduleAtFixedRate(Executors.java:785)
      	at com.mongodb.internal.connection.DefaultConnectionPool$BackgroundMaintenanceManager.start(DefaultConnectionPool.java:1419)
      	at com.mongodb.internal.connection.DefaultConnectionPool$StateAndGeneration.ready(DefaultConnectionPool.java:1500)
      	at com.mongodb.internal.connection.DefaultConnectionPool.ready(DefaultConnectionPool.java:270)
      	at com.mongodb.internal.connection.DefaultSdamServerDescriptionManager.lambda$update$0(DefaultSdamServerDescriptionManager.java:72)
      	at com.mongodb.internal.connection.BaseCluster.withLock(BaseCluster.java:271)
      	at com.mongodb.internal.connection.AbstractMultiServerCluster.withLock(AbstractMultiServerCluster.java:50)
      	at com.mongodb.internal.connection.DefaultSdamServerDescriptionManager.update(DefaultSdamServerDescriptionManager.java:60)
      	at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:165)
      	at java.base/java.lang.Thread.run(Thread.java:829)
      java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@3912c812[Not completed, task = java.util.concurrent.Executors$RunnableAdapter@782fc229[Wrapped task = com.mongodb.internal.connection.DefaultConnectionPool$BackgroundMaintenanceManager$$Lambda$194/0x00000008003b9440@7c1059f4]] rejected from java.util.concurrent.ScheduledThreadPoolExecutor@e59b1a6[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]
      	at java.base/java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2055)
      	at java.base/java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:825)
      	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:340)
      	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor.scheduleAtFixedRate(ScheduledThreadPoolExecutor.java:632)
      	at java.base/java.util.concurrent.Executors$DelegatedScheduledExecutorService.scheduleAtFixedRate(Executors.java:785)
      	at com.mongodb.internal.connection.DefaultConnectionPool$BackgroundMaintenanceManager.start(DefaultConnectionPool.java:1419)
      	at com.mongodb.internal.connection.DefaultConnectionPool$StateAndGeneration.ready(DefaultConnectionPool.java:1500)
      	at com.mongodb.internal.connection.DefaultConnectionPool.ready(DefaultConnectionPool.java:270)
      	at com.mongodb.internal.connection.DefaultSdamServerDescriptionManager.lambda$update$0(DefaultSdamServerDescriptionManager.java:72)
      	at com.mongodb.internal.connection.BaseCluster.withLock(BaseCluster.java:271)
      	at com.mongodb.internal.connection.AbstractMultiServerCluster.withLock(AbstractMultiServerCluster.java:50)
      	at com.mongodb.internal.connection.DefaultSdamServerDescriptionManager.update(DefaultSdamServerDescriptionManager.java:60)
      	at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:165)
      	at java.base/java.lang.Thread.run(Thread.java:829)
      

       

      Sometimes this exception manages to fail my test raising to the main junit thread. other times it stays in the background thread that launched the task. It's really weird.

      Versions:

      • MongoDB 4.4.6 
      • Java 11 / Driver 4.5.1
      • OS X and Linux

       

            Assignee:
            valentin.kovalenko@mongodb.com Valentin Kavalenka
            Reporter:
            flozano@gmail.com Francisco Alejandro Lozano López
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: