{"record":{"id":"161fc5a4aeda3686","repo":"apache/iceberg","slug":"unclosed-input-stream-created-by-161fc5","errorCode":null,"errorMessage":"Unclosed input stream created by:\n\t{}","messagePattern":"Unclosed input stream created by:\n\t(.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"gcp/src/main/java/org/apache/iceberg/gcp/gcs/GCSInputStream.java","lineNumber":223,"sourceCode":"  }\n\n  @Override\n  public void close() throws IOException {\n    super.close();\n    closed = true;\n    if (channel != null) {\n      channel.close();\n    }\n  }\n\n  @SuppressWarnings({\"checkstyle:NoFinalizer\", \"Finalize\", \"deprecation\"})\n  @Override\n  protected void finalize() throws Throwable {\n    super.finalize();\n    if (!closed) {\n      close(); // releasing resources is more important than printing the warning\n      String trace = Joiner.on(\"\\n\\t\").join(Arrays.copyOfRange(createStack, 1, createStack.length));\n      LOG.warn(\"Unclosed input stream created by:\\n\\t{}\", trace);\n    }\n  }\n}\n","sourceCodeStart":205,"sourceCodeEnd":227,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/gcp/src/main/java/org/apache/iceberg/gcp/gcs/GCSInputStream.java#L205-L227","documentation":"GCSInputStream.finalize detects that the stream was garbage-collected without close() ever being called. As a last resort it closes the underlying GCS read channel to release the connection, and logs this warning including the creation-time stack trace so the developer can find the leak site.","triggerScenarios":"Creating a GCSInputStream via GCSFileIO.newInputFile(...).newStream() and never calling close(), then letting it become unreachable; e.g. missing try-with-resources or an exception path skipping close.","commonSituations":"Reading data files or manifests with ad-hoc code that omits try-with-resources; early returns/exceptions between open and close; leaking streams in UDFs or Spark task code.","solutions":["Wrap the stream in try-with-resources so close() is always called","Follow the stack trace in the warning to the leak site and add close/finally","Check exception paths that bypass close (e.g. close only on success)","After fixing, confirm the warning no longer appears in logs"],"exampleFix":"// before\nInputStream in = file.newStream();\nbyte[] data = in.readAllBytes();\n// after\ntry (InputStream in = file.newStream()) {\n  byte[] data = in.readAllBytes();\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try (InputStream in = file.newStream()) { consume(in); } catch (IOException e) { throw new UncheckedIOException(e); }","preventionTips":["Always try-with-resources on streams","Never assign streams to wide-scoped fields","Enable the finalize warning triage via creation stack trace","Review code that opens streams in loops"],"tags":["gcs","resource-leak","stream","finalize"],"backgroundTag":"resource-leak","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}