Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8277969

HttpClient SelectorManager shuts down when custom Executor rejects a task

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 19
    • 18
    • core-libs
    • None
    • b19

      If a HttpClient is created with an Executor to run async and dependent tasks, and if the Executor rejects a task (throws RejectedExecutionException), then the internal SelectorManager may silently shutdown, leaving clients hanging.

      The exception is revealed by running with -Djdk.httpclient.HttpClient.log=all
      Nov 30, 2021 7:03:35 AM jdk.internal.net.http.HttpClientImpl$SelectorManager run
      INFO: CHANNEL: HttpClient-1-SelectorManager: stopping
      Nov 30, 2021 7:03:35 AM jdk.internal.net.http.HttpClientImpl$SelectorManager shutdown
      INFO: MISC: HttpClient-1-SelectorManager: shutting down
      Nov 30, 2021 7:03:35 AM jdk.internal.net.http.HttpClientImpl$SelectorManager run
      INFO: ERROR: HttpClient-2-SelectorManager: HttpClientImpl shutting down due to fatal error: java.util.concurrent.RejectedExecutionException: java.lang.IllegalStateException: Current thread not owner or thread in flock
      at java.base/java.util.concurrent.StructuredExecutor.execute(StructuredExecutor.java:465)
      at java.net.http/jdk.internal.net.http.HttpClientImpl$DelegatingExecutor.execute(HttpClientImpl.java:153)
      at java.net.http/jdk.internal.net.http.PlainHttpConnection$ConnectEvent.handle(PlainHttpConnection.java:152)
      at java.net.http/jdk.internal.net.http.HttpClientImpl$SelectorManager.handleEvent(HttpClientImpl.java:977)
      at java.net.http/jdk.internal.net.http.HttpClientImpl$SelectorManager.lambda$run$3(HttpClientImpl.java:932)
      at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
      at java.net.http/jdk.internal.net.http.HttpClientImpl$SelectorManager.run(HttpClientImpl.java:932)
      Caused by: java.lang.IllegalStateException: Current thread not owner or thread in flock
      at java.base/jdk.internal.misc.ThreadFlock.ensureOwnerOrContainsThread(ThreadFlock.java:204)
      at java.base/jdk.internal.misc.ThreadFlock.start(ThreadFlock.java:267)
      at java.base/java.util.concurrent.StructuredExecutor.spawn(StructuredExecutor.java:345)
      at java.base/java.util.concurrent.StructuredExecutor.execute(StructuredExecutor.java:461)
      ... 6 more

      This issue is created to examine this scenario, e.g.

      - The REE is fatal so maybe the shutdown/exception should be printed to the console unconditionally, irrespective of whether logging is enabled or not.

      - Maybe the spec for HttpClient.Builder.executor(Executor) should specify that the behavior is unspecified when an executor rejects tasks.

      - Maybe there needs to be a fallback to at least complete exceptionally the CF that the client is waiting on, so they aren't hanging indefinitely.

            dfuchs Daniel Fuchs
            alanb Alan Bateman
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: