{"record":{"id":"20d927580115fe2e","repo":"apache/hadoop","slug":"name-stream-is-closed","errorCode":null,"errorMessage":"name + \": Stream is closed!\"","messagePattern":"name \\+ \": Stream is closed!\"","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/prefetch/S3ARemoteInputStream.java","lineNumber":456,"sourceCode":"  public boolean markSupported() {\n    return false;\n  }\n\n  @Override\n  public String toString() {\n    if (isClosed()) {\n      return \"closed\";\n    }\n\n    StringBuilder sb = new StringBuilder();\n    sb.append(String.format(\"nextReadPos = (%d)%n\", nextReadPos));\n    sb.append(String.format(\"fpos = (%s)\", fpos));\n    return sb.toString();\n  }\n\n  protected void throwIfClosed() throws IOException {\n    if (closed) {\n      throw new IOException(\n          name + \": \" + FSExceptionMessages.STREAM_IS_CLOSED);\n    }\n  }\n\n  protected void throwIfInvalidSeek(long pos) throws EOFException {\n    if (pos < 0) {\n      throw new EOFException(FSExceptionMessages.NEGATIVE_SEEK + \" \" + pos);\n    } else if (pos > this.getBlockData().getFileSize()) {\n      throw new EOFException(FSExceptionMessages.CANNOT_SEEK_PAST_EOF + \" \" + pos);\n    }\n  }\n\n  // Unsupported functions.\n\n  @Override\n  public void mark(int readlimit) {\n    throw new UnsupportedOperationException(\"mark not supported\");\n  }","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/prefetch/S3ARemoteInputStream.java#L438-L474","documentation":"S3ARemoteInputStream is the seekable local-facing stream that S3APrefetchingInputStream reads cached/fetched block data through. throwIfClosed() throws IOException(\"<name>: Stream is closed!\") when any read/seek happens after closed=true. Users rarely see it directly; it surfaces when the prefetching stream or test code touches the inner stream post-close.","triggerScenarios":"read()/seek()/getPos() on the S3ARemoteInputStream after close(); prefetch stream teardown racing a queued block-read thread; tests retaining the remote stream after closing the enclosing prefetching input stream.","commonSituations":"Prefetch shutdown races under heavy concurrency (task close while a data block read is in flight); unit tests of S3ARemoteInputStream; custom code extracting the inner stream via reflection/debugging and using it after the owner closed.","solutions":["Do not use the S3ARemoteInputStream directly - perform all I/O through S3APrefetchingInputStream.","Ensure clean shutdown of reader threads before closing the prefetching stream (let in-flight block fetches finish or cancel cleanly).","Catch IOException and inspect for 'Stream is closed' to distinguish lifecycle bugs from S3 errors.","Upgrade hadoop-aws - shutdown races around prefetch threads have been the subject of fixes."],"exampleFix":"// before\nS3ARemoteInputStream remote = ...;\nremote.close();\nremote.read(); // IOException: <name>: Stream is closed!\n\n// after\nif (!remote.isClosed()) {\n  remote.read();\n}","handlingStrategy":"validation","validationCode":"// test-only style guard if you hold the inner stream directly\nif (!remote.isClosed()) {\n  remote.read(buf, off, len);\n}","typeGuard":null,"tryCatchPattern":"try {\n  remote.read(buf, off, len);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"Stream is closed\")) {\n    // stop the reader thread / reopen the enclosing prefetch stream\n  } else { throw e; }\n}","preventionTips":["Interact only with the public FSDataInputStream, not the internal remote stream.","Shut down block-read executors before closing the prefetching stream.","Keep hadoop-aws current - prefetch shutdown races have been fixed over time."],"tags":["hadoop-aws","prefetch","stream-lifecycle","use-after-close"],"backgroundTag":"io-stream-already-closed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}