{"record":{"id":"b2cdcde3fca77498","repo":"apache/beam","slug":"exception-destroying-pooled-object","errorCode":null,"errorMessage":"Exception destroying pooled object.","messagePattern":"Exception destroying pooled object\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"sdks/java/io/amazon-web-services2/src/main/java/org/apache/beam/sdk/io/aws2/common/ObjectPool.java","lineNumber":89,"sourceCode":"\n  /**\n   * Release a reference to a shared object instance using {@link KeyT}. If that instance is not\n   * used anymore, it will be removed and destroyed.\n   */\n  public void releaseByKey(KeyT key) {\n    RefCounted ref;\n    synchronized (pool) {\n      ref = pool.get(key);\n      if (ref == null || --ref.count > 0) {\n        return;\n      }\n      pool.remove(key);\n    }\n    if (finalizer != null) {\n      try {\n        finalizer.accept(ref.shared);\n      } catch (Exception e) {\n        LoggerFactory.getLogger(ObjectPool.class).warn(\"Exception destroying pooled object.\", e);\n      }\n    }\n  }\n\n  /**\n   * Release a reference to a shared client instance. If that instance is not used anymore, it will\n   * be removed and destroyed.\n   */\n  public void release(ObjectT object) {\n    KeyT key = pool.inverse().get(new RefCounted(object));\n    if (key != null) {\n      releaseByKey(key);\n    }\n  }\n\n  public static <ClientT extends SdkClient, BuilderT extends AwsClientBuilder<BuilderT, ClientT>>\n      ClientPool<ClientT> pooledClientFactory(BuilderT builder) {\n    return new ClientPool<>(c -> buildClient(c.getLeft(), builder, c.getRight()));","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/amazon-web-services2/src/main/java/org/apache/beam/sdk/io/aws2/common/ObjectPool.java#L71-L107","documentation":"ObjectPool (shared AWS client pooling for Beam's aws2 IO) logs this warning when the finalizer/destroyer accept(...) for a pooled shared object (e.g. an AWS SDK client) throws while releasing a reference whose refcount dropped to zero. The pool removes the entry regardless; only the cleanup of the underlying resource failed, potentially leaking connections or threads.","triggerScenarios":"releaseByKey drops the last reference and invokes the registered finalizer (typically client.close()); the close throws — e.g. an SDK client's close failing on an in-flight request, an IOException shutting down a connection pool, or a custom finalizer that throws.","commonSituations":"Shutting down pipelines while async clients still have pending requests; custom ObjectPool finalizers with buggy cleanup logic; AWS SDK close-time failures under network faults.","solutions":["Inspect the logged cause; if it is an SDK close failure, ensure no writes are still in flight before the pool is released (flush/await completion first).","If a custom finalizer was registered, wrap its cleanup logic so exceptions during close are contained or idempotent.","This is a cleanup-time warning: the pool already removed the object; verify no resource leak grows over the job (thread/connection counts) and ignore if benign."],"exampleFix":"// before: finalizer that can throw\nfinalizer = client -> client.close();\n// after: idempotent, exception-safe cleanup\nfinalizer = client -> {\n  try { client.close(); } catch (RuntimeException e) { LOG.debug(\"client close ignored\", e); }\n};","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// contain cleanup exceptions in finalizers registered with ObjectPool\npool.register(key, client, shared -> {\n  try { shared.close(); } catch (Exception e) { LOG.debug(\"ignore close failure\", e); }\n});","preventionTips":["Await completion of in-flight async requests before releasing pooled clients","Make client finalizers idempotent and exception-safe","Monitor thread/connection counts for leaks if this warning recurs"],"tags":["java","apache-beam","aws","resource-cleanup","object-pool"],"backgroundTag":"resource-cleanup-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}