You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "lhotari (via GitHub)" <gi...@apache.org> on 2026/10/14 06:38:58 UTC

[PR] [fix][broker] Fix web service close hang when the Jetty server fails to start [pulsar]

lhotari opened a new pull request, #26895:
URL: https://github.com/apache/pulsar/pull/26895

   ### Motivation
   
   A `BROKER_CLIENT_API` unit test job was cancelled after hitting the 1-hour timeout ([run](https://github.com/apache/pulsar/actions/runs/38420164294/job/115464397582)). The thread dump shows the test worker parked for over 35 minutes in `PulsarMultiListenersWithInternalListenerNameTest.setup()`. Broker startup had failed, and the cleanup that closes a failed `PulsarService` never returned:
   
   ```
   at java.util.concurrent.ThreadPoolExecutor.awaitTermination(ThreadPoolExecutor.java:1421)
   at org.eclipse.jetty.util.thread.ExecutorThreadPool.join(ExecutorThreadPool.java:331)
   at org.apache.pulsar.broker.web.WebService.doClose(WebService.java:544)
   at org.apache.pulsar.broker.web.WebService.close(WebService.java:513)
   at org.apache.pulsar.broker.PulsarService.closeAsync(PulsarService.java:573)
   ...
   at org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest.startBroker(MockedPulsarServiceBaseTest.java:408)
   ```
   
   `ExecutorThreadPool.join()` calls `awaitTermination(Long.MAX_VALUE)`, and the executor is only shut down in `ExecutorThreadPool.doStop()`. In Jetty 12, `Server.doStart()` opens its network connectors (`openEarly=true` by default) before it starts its beans. When a connector fails to bind, for example because the port is already in use, `Server.start()` throws while the thread pool is still unstarted. `server.stop()` then skips stopping the pool because its state is still `STOPPED`, so the executor is never shut down and `join()` blocks forever. The thread dump agrees: no thread of the pool being joined was alive.
   
   This test is exposed because it reserves ports with `getFreePorts()`, releases them, and the broker binds them later. Another process can take a port in between. The same hang can happen to any broker whose web server fails to start.
   
   ### Modifications
   
   - `WebExecutorThreadPool` records that a start was attempted in `doStart()`, and `join()` returns immediately for a pool that was never started. A pool whose start was attempted keeps the existing semantics. Stopping a pool whose start failed still runs `doStop()`, which shuts the executor down, so `join()` returns.
   - The fix is in `pulsar-broker-common`, so the proxy, websocket and functions worker web servers that use the same pool are covered as well.
   
   ### Verifying this change
   
   - [ ] Make sure that the change passes the CI checks.
   
   This change added tests and can be verified as follows:
     - Added `WebExecutorThreadPoolTest.testJoinReturnsAfterServerFailsToBindPort`, which starts a `Server` whose connector targets an occupied port, stops it, and asserts that `join()` completes. Without the fix, `join()` does not complete and the test fails.
     - Added `WebExecutorThreadPoolTest.testJoinReturnsAfterStartedPoolIsStopped` for the normal start/stop path.
     - `PulsarMultiListenersWithInternalListenerNameTest` and `WebServiceTest` pass locally.
   
   ### Does this pull request potentially affect one of the following parts:
   
   *If the box was checked, please highlight the changes*
   
   - [ ] Dependencies (add or upgrade a dependency)
   - [ ] The public API
   - [ ] The schema
   - [ ] The default values of configurations
   - [ ] The threading model
   - [ ] The binary protocol
   - [ ] The REST endpoints
   - [ ] The admin CLI options
   - [ ] The metrics
   - [ ] Anything that affects deployment
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [fix][broker] Fix web service close hang when the Jetty server fails to start [pulsar]

Posted by "merlimat (via GitHub)" <gi...@apache.org>.
merlimat merged PR #26895:
URL: https://github.com/apache/pulsar/pull/26895


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org