{"record":{"id":"b751968f501106bf","repo":"apache/druid","slug":"background-lookup-manager-thread-could-not-be-canc","errorCode":null,"errorMessage":"Background lookup manager thread could not be cancelled","messagePattern":"Background lookup manager thread could not be cancelled","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server/src/main/java/org/apache/druid/server/lookup/cache/LookupCoordinatorManager.java","lineNumber":464,"sourceCode":"        //so that subsequent stop() would happen, even if start() failed with exception\n        lifecycleLock.started();\n        lifecycleLock.exitStart();\n      }\n    }\n  }\n\n  public void stop()\n  {\n    synchronized (lifecycleLock) {\n      if (!lifecycleLock.canStop()) {\n        throw new ISE(\"LookupCoordinatorManager can't stop.\");\n      }\n\n      try {\n        LOG.debug(\"Stopping\");\n\n        if (backgroundManagerFuture != null && !backgroundManagerFuture.cancel(true)) {\n          LOG.warn(\"Background lookup manager thread could not be cancelled\");\n        }\n\n        // signal the executorService to shut down ASAP, if this coordinator becomes leader again\n        // then start() would ensure that this executorService is finished before starting a\n        // new one.\n        if (executorService != null) {\n          executorService.shutdownNow();\n        }\n\n        LOG.debug(\"Stopped\");\n      }\n      catch (Exception ex) {\n        LOG.makeAlert(ex, \"Got Exception while stop()\").emit();\n      }\n      finally {\n        //so that subsequent start() would happen, even if stop() failed with exception\n        lifecycleLock.exitStopAndReset();\n      }","sourceCodeStart":446,"sourceCodeEnd":482,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/server/src/main/java/org/apache/druid/server/lookup/cache/LookupCoordinatorManager.java#L446-L482","documentation":"LookupCoordinatorManager.stop() attempts to cancel the background lookup management loop via backgroundManagerFuture.cancel(true). If the future cannot be cancelled (already completed normally or cancellation was rejected), a warning is logged. This is not an exception; it is a diagnostic that the background thread shut down by its own means instead of being interrupted.","triggerScenarios":"Calling stop() when the background management loop has already finished executing (future completed), or when the scheduled task rejected cancellation.","commonSituations":"Race where the loop exits on its own while stop() runs; repeated start/stop cycles in tests or leader handoff; coordinator losing and regaining leadership quickly.","solutions":["Verify the background task is not exiting prematurely; check for exceptions swallowed in lookupManagementLoop.","If expected during shutdown, treat this log as informational; no action needed.","Check executorService shutdown logic in stop()/start() to ensure futures are recreated on restart."],"exampleFix":"// before\nif (backgroundManagerFuture != null && !backgroundManagerFuture.cancel(true)) {\n  LOG.warn(\"Background lookup manager thread could not be cancelled\");\n}\n// after\nif (backgroundManagerFuture != null && !backgroundManagerFuture.isDone() && !backgroundManagerFuture.cancel(true)) {\n  LOG.warn(\"Background lookup manager thread could not be cancelled\");\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// treat as informational\nif (backgroundManagerFuture != null && !backgroundManagerFuture.isDone()) {\n  boolean cancelled = backgroundManagerFuture.cancel(true);\n  LOG.debug(\"cancelled=%s\", cancelled);\n}","preventionTips":["Check isDone() before cancel to distinguish natural completion from failed cancellation","Ensure start()/stop() pairs are balanced under leader handoff","Log at debug in expected shutdown paths"],"tags":["concurrency","thread-lifecycle","shutdown"],"backgroundTag":"thread-interrupt-failed","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"}