{"record":{"id":"1c1cbb7ab0daf5e2","repo":"eclipse-vertx/vert.x","slug":"resource-manager-shutdown","errorCode":null,"errorMessage":"Resource manager shutdown","messagePattern":"Resource manager shutdown","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"vertx-core/src/main/java/io/vertx/core/internal/resource/ResourceManager.java","lineNumber":110,"sourceCode":"  /**\n   * Get a resource resolved by {@code key}\n   *\n   * @param key the resource key\n   * @return the future resolved with the resource\n   */\n  public <T> Future<T> withResourceAsync(K key, Function<K, R> provider, BiFunction<R, Boolean, Future<T>> function) {\n    return withResource(key, provider, Function.identity(), (res, created) -> {\n      if (res.before()) {\n        return function.apply(res, created).andThen(ar -> res.after());\n      }\n      return null;\n    });\n  }\n\n  private void checkStatus() {\n    int st = status.get();\n    if (st == 1) {\n      throw new IllegalStateException(\"Resource manager shutdown\");\n    } else if (st == 2) {\n      throw new IllegalStateException(\"Resource manager closed\");\n    }\n  }\n\n  /**\n   * Shutdown the resource manager: any new request will be rejected.\n   */\n  public void shutdown() {\n    if (status.compareAndSet(0, 1)) {\n      for (ManagedResource resource : resources.values()) {\n        resource.shutdown();\n      }\n      status.set(2);\n    }\n  }\n\n  /**","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/internal/resource/ResourceManager.java#L92-L128","documentation":"ResourceManager tracks its lifecycle with a status counter; checkStatus() rejects any operation once the manager has been shut down (status 1). withResource() (and other entry points) therefore throws this IllegalStateException when a resource is requested after shutdown() was called. Shutdown only rejects new requests; it does not mean the manager was used incorrectly, only that it is no longer accepting work.","triggerScenarios":"Calling withResource (or acquiring a resource) after ResourceManager.shutdown() has been invoked — e.g. a Vertx instance/Context was closed while background code still submits work, a connection provider's resource manager was shut down on close, or a race where a task queued before shutdown runs after it.","commonSituations":"Closing a Vertx instance (vertx.close()) while in-flight requests still try to create connections; using a shared/cached client whose underlying manager was closed; tests that close the Vertx context in @AfterEach while async assertions still run.","solutions":["Ensure all work using the manager completes before calling shutdown(); await completion of in-flight operations (futures) prior to close","Do not reuse a closed Vertx instance or closed client; create a new Vertx/client instance after close","Guard submissions with a lifecycle check (isShutdown flag) and skip/requeue instead of calling withResource after shutdown","Catch IllegalStateException from withResource and treat it as 'shutting down' — abort the operation gracefully rather than retrying"],"exampleFix":"// before\nvertx.close();\nclient.request() // later background task -> IllegalStateException: Resource manager shutdown\n// after\nrequestFuture.compose(ok -> vertx.close()); // close only after work completes","handlingStrategy":"try-catch","validationCode":"// track shutdown state of the owning Vertx/client before submitting work\nif (vertxIsClosed || manager.isShutdown()) { // e.g. skip or requeue\n  return Future.failedFuture(new CancellationException(\"shutting down\"));\n}","typeGuard":null,"tryCatchPattern":"try {\n  return manager.withResource(key, supplier);\n} catch (IllegalStateException e) {\n  if (\"Resource manager shutdown\".equals(e.getMessage())) {\n    return Future.failedFuture(new CancellationException(\"resource manager shutdown, operation aborted\"));\n  }\n  throw e;\n}","preventionTips":["Sequence shutdown() after all in-flight work completes (compose work futures with the close call)","Never share a Vertx/client across components that close it independently; use reference counting or DI lifecycle hooks","Cancel schedulers and background tasks before shutdown","Do not retry operations that fail with this error — the manager will never accept work again"],"tags":["lifecycle","shutdown","resource-manager","illegal-state"],"backgroundTag":"invalid-state-transition","analyzedSha":"fb308bd8c3f12c79f4ae89bef67fadf6c80d036e","analyzedAt":"2026-09-06T11:37:12.241Z","contentChangedAt":"2026-09-06T11:37:12.241Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}