Skip to content

streams: non-writable Duplex is writable (more annoyance than bug) #34374

Description

@jasnell

@mcollina @ronag @nodejs/streams

const { Duplex } = require('stream');

const d = new Duplex({
  writable: false,
  write(chunk, encoding, cb) {
    console.log(chunk.toString());
    cb();
  }
});

console.log(d.writable);   // false! as expected...

d.write('darn it');  // prints, 'darn it' and returns true

This isn't a bug since it's been like this forever but the behavior is really counter intuitive, especially since after calling d.end() and then doing a d.write() we get a proper write after end error. It makes implementing a custom Duplex (e.g. QuicStream) more difficult because of the additional checks that need to be made to ensure that even tho the Duplex isn't writable no-one is writing to it.

Not sure what the fix is immediately but wanted to discuss it first.

The ideal behavior, I would think, is an error similar to write after end if write() is called on a non-writable Duplex.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

discussIssues opened for discussion and feedback.streamIssues and PRs related to Node.js streams.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions