{"record":{"id":"cc2fde7d520f5b18","repo":"apache/druid","slug":"unable-to-stop-jetty-server","errorCode":null,"errorMessage":"Unable to stop Jetty server.","messagePattern":"Unable to stop Jetty server\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server/src/main/java/org/apache/druid/server/initialization/jetty/JettyServerModule.java","lineNumber":462,"sourceCode":"          public void stop()\n          {\n            try {\n              final long unannounceDelay = config.getUnannouncePropagationDelay().toStandardDuration().getMillis();\n              if (unannounceDelay > 0) {\n                log.info(\"Sleeping %s ms for unannouncement to propagate.\", unannounceDelay);\n                Thread.sleep(unannounceDelay);\n              } else {\n                log.debug(\"Skipping unannounce wait.\");\n              }\n              log.debug(\"Stopping Jetty Server...\");\n              server.stop();\n            }\n            catch (InterruptedException e) {\n              Thread.currentThread().interrupt();\n              throw new RE(e, \"Interrupted waiting for jetty shutdown.\");\n            }\n            catch (Exception e) {\n              log.warn(e, \"Unable to stop Jetty server.\");\n            }\n          }\n        },\n        Lifecycle.Stage.SERVER\n    );\n\n    if (!config.isShowDetailedJettyErrors()) {\n      server.setErrorHandler(new ErrorHandler()\n      {\n        @Override\n        public boolean handle(\n            Request baseRequest,\n            Response response,\n            Callback callback\n        ) throws Exception\n        {\n          baseRequest.setAttribute(RequestDispatcher.ERROR_EXCEPTION, null);\n          return super.handle(baseRequest, response, callback);","sourceCodeStart":444,"sourceCodeEnd":480,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/server/src/main/java/org/apache/druid/server/initialization/jetty/JettyServerModule.java#L444-L480","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the chained exception in the warn log to identify which Jetty handler failed to stop.","Reduce long-running in-flight requests or increase graceful shutdown handling before lifecycle stop.","Remove/fix custom Jetty filters or handlers whose doStop() throws.","If seen only at JVM exit, it is usually harmless; ensure clean lifecycle start/stop ordering in tests (pair StartupInjector/Lifecycle setup)."],"exampleFix":"// before: hung websocket keeps server busy past stop timeout\nServerConnector conn = new ServerConnector(server);\nconn.setSoLingerTime(-1);\n// after: bound idle time so stop() completes within the graceful window\nServerConnector conn = new ServerConnector(server);\nconn.setIdleTimeout(10_000);\nserver.setStopTimeout(5_000);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// The module already catches internally; at embed/extension level:\ntry { lifecycle.stop(); } catch (Exception e) { log.warn(e, \"Non-fatal: jetty stop issue during shutdown\"); }","preventionTips":["Keep in-flight requests short or drain them before shutdown.","Ensure custom handlers/filters implement doStop() without throwing.","Test clean start/stop cycles in integration tests to catch handler stop bugs early."],"tags":["jetty","lifecycle","shutdown","server"],"backgroundTag":"graceful-shutdown-timeout","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}