Skip to content

unpipe() and resume() in _transform() #31190

Description

@utftu
  • Node.js Version: 13.*
  • OS: mac
  • Scope (install, code, runtime, meta, other?):
  • Module (and version) (if relevant):

In case of synchronous pipe removal in _transform, the resume method does not resume as expected

const stream = require('stream')

const fs = require('fs');
const readStream = fs.createReadStream('big.txt')
const writeStream = fs.createWriteStream('result.txt');

const transformStream = new class extends stream.Transform {

  _transform(chunk, encoding, callback) {
    readStream.unpipe()
    readStream.resume()
  }
}

readStream.on('end', () => {
  console.log('never print')
})


readStream
  .pipe(transformStream)
  .pipe(writeStream)

Nevertheless, resume operation during an asynchronous call and removal not from the _transform method

Can someone explain this behavior why unpipe () and resume () do not work in the _transform method?

Activity

  1. transferred this issue fromnodejs/helpon Jan 5, 2020
  2. added
    streamIssues and PRs related to Node.js streams.
    on Jan 5, 2020
  3. addaleax commented on Jan 5, 2020

    @addaleax
    Member

    /cc @ronag

  4. ronag commented on Jan 5, 2020

    @ronag
  5. ronag commented on Jan 5, 2020

    @ronag
  6. addaleax commented on Jan 5, 2020

    @addaleax
    Member

    @ronag The only two things I could think of are a) process.exit() or equivalents being called or b) blocking JS execution that prevents the nextTick queue from running.

    For debugging Node.js core, it’s sometimes a good idea to use process._rawDebug() rather than console.log(), which doesn’t use streams under the hood.

    That being said, if I just add the console.log() calls like you did, it does print output for me.

  7. ronag commented on Jan 5, 2020

    @ronag
    Member

    For debugging Node.js core, it’s sometimes a good idea to use process._rawDebug() rather than console.log()

    Oh, thanks for that! I'll keep digging.

  8. added a commit that references this issue on Jan 5, 2020
  9. added a commit that references this issue on Jan 16, 2020
  10. added a commit that references this issue on Apr 1, 2020
  11. added a commit that references this issue on Apr 1, 2020
  12. added a commit that references this issue on Apr 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    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