ERR_STREAM_PUSH_AFTER_EOF
Node.jsERRORNotableStreamHIGH confidence

Stream push() called after EOF has been emitted

Production Risk

Can crash stream pipelines; ensure stream termination logic is single-path.

What this means

Thrown when stream.push(null) has been called to signal the end of a readable stream, and then stream.push() is called again with additional data. Once null is pushed the stream is in an ended state and no more data can be added.

Why it happens
  1. 1Calling push(null) to end the stream and then pushing more data in a callback
  2. 2Race condition between an async data source and the stream end signal
  3. 3Logic error where stream termination and data production paths are not mutually exclusive
How to reproduce

Triggered when push() is called on a Readable stream after push(null) has already been called.

trigger — this will error
trigger — this will error
const { Readable } = require('stream');
const r = new Readable({ read() {} });
r.push('data');
r.push(null);   // EOF
r.push('more'); // throws ERR_STREAM_PUSH_AFTER_EOF

expected output

Error [ERR_STREAM_PUSH_AFTER_EOF]: stream.push() after EOF

Fix

Track whether EOF has been pushed and guard accordingly

WHEN In custom Readable implementations with async data sources

Track whether EOF has been pushed and guard accordingly
class MyReadable extends Readable {
  constructor() {
    super();
    this._done = false;
  }
  _read() {
    if (this._done) return;
    fetchChunk().then(chunk => {
      if (!chunk) { this._done = true; this.push(null); return; }
      this.push(chunk);
    });
  }
}

Why this works

Using a flag ensures push(null) is called exactly once and no further pushes occur.

Code examples
Triggerjs
const { Readable } = require('stream');
const r = new Readable({ read() {} });
r.push('data');
r.push(null);   // EOF
r.push('more'); // throws ERR_STREAM_PUSH_AFTER_EOF  // this triggers ERR_STREAM_PUSH_AFTER_EOF
Handle in try/catchjs
try {
  // operation that may throw ERR_STREAM_PUSH_AFTER_EOF
  riskyOperation()
} catch (err) {
  if (err.code === 'ERR_STREAM_PUSH_AFTER_EOF') {
    console.error('ERR_STREAM_PUSH_AFTER_EOF:', err.message)
  } else {
    throw err
  }
}
Defensive pattern to avoid itjs
// Validate inputs before calling the operation
function safe_err_stream_push_after_eof(...args) {
  // validate args here
  return performOperation(...args)
}
What not to do

Push null and then push more data

Once EOF is signalled the stream is sealed; further pushes are illegal.

Same error in other languages
Sources
Official documentation ↗

Node.js Error Codes Documentation

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Node.js errors