{"record":{"id":"7bf3f650b780217f","repo":"apache/hadoop","slug":"the-stream-is-closed","errorCode":null,"errorMessage":"The stream is closed","messagePattern":"The stream is closed","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/SocketOutputStream.java","lineNumber":117,"sourceCode":"  }\n  \n  @Override\n  public void write(int b) throws IOException {\n    /* If we need to, we can optimize this allocation.\n     * probably no need to optimize or encourage single byte writes.\n     */\n    byte[] buf = new byte[1];\n    buf[0] = (byte)b;\n    write(buf, 0, 1);\n  }\n  \n  @Override\n  public void write(byte[] b, int off, int len) throws IOException {\n    ByteBuffer buf = ByteBuffer.wrap(b, off, len);\n    while (buf.hasRemaining()) {\n      try {\n        if (write(buf) < 0) {\n          throw new IOException(\"The stream is closed\");\n        }\n      } catch (IOException e) {\n        /* Unlike read, write can not inform user of partial writes.\n         * So will close this if there was a partial write.\n         */\n        if (buf.capacity() > buf.remaining()) {\n          writer.close();\n        }\n        throw e;\n      }\n    }\n  }\n\n  @Override\n  public synchronized void close() throws IOException {\n    /* close the channel since Socket.getOuputStream().close() \n     * closes the socket.\n     */","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/SocketOutputStream.java#L99-L135","documentation":"Error \"The stream is closed\" thrown in apache/hadoop.","triggerScenarios":"Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/SocketOutputStream.java:117 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Do not write to the stream after close() has been called; check the calling code for use-after-close.","Ensure only one thread closes the stream and that writes are synchronized with the close operation.","Reconnect and obtain a new stream if the connection was closed due to a prior error or timeout."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}