apache/druid · warning

Unable to stop Jetty server.

Error message

Unable to stop Jetty server.

What it means

During Druid server shutdown, the Jetty server stop is executed in a Lifecycle stop hook. If stopping the Jetty Server throws (after a 5-second graceful shutdown wait), the module logs this warning. It does not abort shutdown; it means some HTTP resources (servlets, handlers) may not have closed cleanly.

Solutions

  1. Check the chained exception in the warn log to identify which Jetty handler failed to stop.
  2. Reduce long-running in-flight requests or increase graceful shutdown handling before lifecycle stop.
  3. Remove/fix custom Jetty filters or handlers whose doStop() throws.
  4. If seen only at JVM exit, it is usually harmless; ensure clean lifecycle start/stop ordering in tests (pair StartupInjector/Lifecycle setup).

Example fix

// before: hung websocket keeps server busy past stop timeout
ServerConnector conn = new ServerConnector(server);
conn.setSoLingerTime(-1);
// after: bound idle time so stop() completes within the graceful window
ServerConnector conn = new ServerConnector(server);
conn.setIdleTimeout(10_000);
server.setStopTimeout(5_000);
Defensive patterns

Strategy: try-catch

Try / catch

// The module already catches internally; at embed/extension level:
try { lifecycle.stop(); } catch (Exception e) { log.warn(e, "Non-fatal: jetty stop issue during shutdown"); }

Prevention

When it happens

Trigger: Lifecycle stop calls jettyServer.stop() and Jetty throws an Exception while stopping handlers/context after the graceful shutdown timeout expires or a handler fails to stop.

Common situations: Long-running HTTP requests or WebSockets not finishing within the 5s stop timeout; custom filters/handlers throwing in their own stop callbacks; interrupted JVM shutdown sequencing.

Related errors


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/cc2fde7d520f5b18. Report an issue: GitHub.

Appendix: source

Thrown at server/src/main/java/org/apache/druid/server/initialization/jetty/JettyServerModule.java:462

          public void stop()
          {
            try {
              final long unannounceDelay = config.getUnannouncePropagationDelay().toStandardDuration().getMillis();
              if (unannounceDelay > 0) {
                log.info("Sleeping %s ms for unannouncement to propagate.", unannounceDelay);
                Thread.sleep(unannounceDelay);
              } else {
                log.debug("Skipping unannounce wait.");
              }
              log.debug("Stopping Jetty Server...");
              server.stop();
            }
            catch (InterruptedException e) {
              Thread.currentThread().interrupt();
              throw new RE(e, "Interrupted waiting for jetty shutdown.");
            }
            catch (Exception e) {
              log.warn(e, "Unable to stop Jetty server.");
            }
          }
        },
        Lifecycle.Stage.SERVER
    );

    if (!config.isShowDetailedJettyErrors()) {
      server.setErrorHandler(new ErrorHandler()
      {
        @Override
        public boolean handle(
            Request baseRequest,
            Response response,
            Callback callback
        ) throws Exception
        {
          baseRequest.setAttribute(RequestDispatcher.ERROR_EXCEPTION, null);
          return super.handle(baseRequest, response, callback);

View on GitHub (pinned to 9b90983fd2)