{"record":{"id":"91238c2d877c8b9d","repo":"apache/iceberg","slug":"failed-to-close-s3seekableinputstreamfactory","errorCode":null,"errorMessage":"Failed to close S3SeekableInputStreamFactory","messagePattern":"Failed to close S3SeekableInputStreamFactory","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"aws/src/main/java/org/apache/iceberg/aws/s3/AnalyticsAcceleratorUtil.java","lineNumber":91,"sourceCode":"  private static S3SeekableInputStreamFactory createNewFactory(\n      Pair<S3AsyncClient, S3FileIOProperties> cacheKey) {\n    ConnectorConfiguration connectorConfiguration =\n        new ConnectorConfiguration(cacheKey.second().s3AnalyticsacceleratorProperties());\n    S3SeekableInputStreamConfiguration streamConfiguration =\n        S3SeekableInputStreamConfiguration.fromConfiguration(connectorConfiguration);\n    ObjectClientConfiguration objectClientConfiguration =\n        ObjectClientConfiguration.fromConfiguration(connectorConfiguration);\n\n    ObjectClient objectClient = new S3SdkObjectClient(cacheKey.first(), objectClientConfiguration);\n    return new S3SeekableInputStreamFactory(objectClient, streamConfiguration);\n  }\n\n  private static void close(S3SeekableInputStreamFactory factory) {\n    if (factory != null) {\n      try {\n        factory.close();\n      } catch (IOException e) {\n        LOG.warn(\"Failed to close S3SeekableInputStreamFactory\", e);\n      }\n    }\n  }\n\n  public static void cleanupCache(\n      S3AsyncClient asyncClient, S3FileIOProperties s3FileIOProperties) {\n    STREAM_FACTORY_CACHE.invalidate(Pair.of(asyncClient, s3FileIOProperties));\n  }\n}\n","sourceCodeStart":73,"sourceCodeEnd":101,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/aws/src/main/java/org/apache/iceberg/aws/s3/AnalyticsAcceleratorUtil.java#L73-L101","documentation":"A warning from AnalyticsAcceleratorUtil's static STREAM_FACTORY_CACHE cleanup: closing the cached S3SeekableInputStreamFactory threw an IOException. The factory (used by the S3 Analytics Accelerator for seekable reads) could not release its resources cleanly; the warning is logged and close proceeds silently otherwise.","triggerScenarios":"Cleanup cache eviction (STREAM_FACTORY_CACHE removal callback) or explicit cleanupCache() invoking factory.close() while the factory's underlying resources (clients, buffers) are in a bad state, e.g. already partially closed or its async client failing shutdown.","commonSituations":"JVM shutdown with the cache still holding factories; swapping S3FileIOProperties (region/endpoint changes) causing cache eviction; closing a factory whose underlying S3AsyncClient was already shut down by user code.","solutions":["Check the logged IOException cause; if it's the async client shutdown, ensure the S3AsyncClient passed to cleanupCache outlives the factory","Call AnalyticsAcceleratorUtil.cleanupCache explicitly during application shutdown to close factories in a controlled state","Avoid reusing a factory after its close attempt; re-acquire via the cache","If repeated, disable the analytics-accelerator feature via S3FileIOProperties if you don't need it"],"exampleFix":"// before\nS3AsyncClient client = S3AsyncClient.create();\nclient.close(); // closed before factory cleanup -> factory.close() throws\nAnalyticsAcceleratorUtil.cleanupCache(client, props);\n// after\nS3AsyncClient client = S3AsyncClient.create();\nAnalyticsAcceleratorUtil.cleanupCache(client, props); // close factory first\nclient.close();","handlingStrategy":"try-catch","validationCode":"// ensure the client passed to cleanupCache is still open\nif (!asyncClientIsShutdown) {\n  AnalyticsAcceleratorUtil.cleanupCache(asyncClient, s3FileIOProperties);\n}","typeGuard":"boolean factoryClosable = factory != null; // mirror the util's null guard","tryCatchPattern":null,"preventionTips":["Close the stream factory cache before shutting down the S3AsyncClient","Call cleanupCache during orderly application shutdown","Don't share one S3AsyncClient's lifecycle across multiple FileIO instances with different properties","Read the logged IOException cause to identify which resource failed to close"],"tags":["aws","s3","resource-cleanup","analytics-accelerator"],"backgroundTag":"resource-cleanup-failed","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}