{"record":{"id":"4f29af25064ae55e","repo":"apache/hadoop","slug":"stream-is-closed-4f29af","errorCode":null,"errorMessage":"Stream is closed!","messagePattern":"Stream is closed!","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-cloud-storage-project/hadoop-tos/src/main/java/org/apache/hadoop/fs/tosfs/object/ObjectRangeInputStream.java","lineNumber":188,"sourceCode":"\n    closeStream();\n    stream = openStream(nextPos, range.end() - nextPos);\n  }\n\n  private InputStream openStream(long offset, long limit) throws IOException {\n    return storage.get(objectKey, offset, limit).verifiedStream(checksum);\n  }\n\n  private void closeStream() throws IOException {\n    if (stream != null) {\n      stream.close();\n    }\n    stream = null;\n  }\n\n  private void checkNotClosed() throws IOException {\n    if (closed) {\n      throw new IOException(FSExceptionMessages.STREAM_IS_CLOSED);\n    }\n  }\n\n  public boolean include(long pos) {\n    return range.include(pos);\n  }\n\n  public Range range() {\n    return range;\n  }\n}\n","sourceCodeStart":170,"sourceCodeEnd":200,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-cloud-storage-project/hadoop-tos/src/main/java/org/apache/hadoop/fs/tosfs/object/ObjectRangeInputStream.java#L170-L200","documentation":"ObjectRangeInputStream serves a single HTTP range of an object inside the multi-range reader. Once its plain boolean closed flag is set, any subsequent operation hits checkNotClosed() and throws IOException(\"Stream is closed!\") (FSExceptionMessages.STREAM_IS_CLOSED). Unlike the outer stream it has no AtomicBoolean and no async close, but the semantics are identical: use-after-close.","triggerScenarios":"Reading from an ObjectRangeInputStream after the enclosing reader (or a test) closed it; calling read past the range after closeStream() has swapped or cleared the underlying stream.","commonSituations":"Custom code or tests that extract and hold inner range streams; interleaved close/read when concurrent readers share range streams; eager close in unit tests.","solutions":["Never hold or reuse inner range streams after the parent ObjectMultiRangeInputStream closed","Route all reads through the owning stream rather than inner chunks","Catch and tolerate this IOException during cancellation/shutdown paths"],"exampleFix":"// before\nObjectRangeInputStream range = ...; // inner chunk stream\nrange.close();\nrange.read(buf); // IOException: Stream is closed!\n\n// after: only the owner stream is used and closed\ntry (ObjectMultiRangeInputStream in = storage.openStream(...)) {\n  in.read(buf);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  rangeStream.read(buf);\n} catch (IOException e) {\n  if (FSExceptionMessages.STREAM_IS_CLOSED.equals(e.getMessage())) {\n    // inner range stream already closed by its owner: stop using it\n    return;\n  }\n  throw e;\n}","preventionTips":["Never hold inner ObjectRangeInputStream instances beyond the parent reader's lifetime","Route all reads through the owning multi-range stream","Close streams exactly once, from one owner"],"tags":["hadoop-tos","object-storage","input-stream","use-after-close","range-read"],"backgroundTag":"stream-already-closed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}