Skip to content

pipeline causes script to silently crash #38539

Closed
@webdevlocalhost

Description

@webdevlocalhost

Version: 16
Platform: Linux webdev-g7 5.4.0-72-generic #80-Ubuntu SMP Mon Apr 12 17:35:00 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

const fs = require('fs')
const { pipeline:pipelineSync } = require('stream')
const { promisify } = require('util')
const pipeline = promisify(pipelineSync)

// I'm targeting v14.14 which doesn't have stream/promises
// const { pipeline } = require('stream/promises')

// The goal with this script was _testing_ if an append file descriptor
// could be reused in pipeline to append one file then another, just to see...
// however the script fails silently no error
// doing an --inspect-brk looks like it gets stuck in some active hooks loop
// but I'm not sure... I tested with 14.14 and 15, 16 versions

async function main() {
  debugger
  await fs.promises.writeFile('tmp/a', Buffer.alloc(1024, 0x0d))
  await fs.promises.writeFile('tmp/b', Buffer.alloc(1024, 0x0a))

  try {
    const fh = await fs.promises.open('tmp/c', 'a')
    // Create write stream that doesn't close from "append" file handler
    const output = fs.createWriteStream(null, { fd: fh.fd, autoClose: false })
    // append contents from tmp/a
    const readA = fs.createReadStream('tmp/a')
    await pipeline(readA, output)
    // append contents from tmp/b but script silently fails here
    // console.log('done.') never fires
    // no exceptions get thrown
    const readB = fs.createReadStream('tmp/b')
    await pipeline(readB, output)
    await fh.close()
  } catch (e) {
    console.log(e)
  }

  console.log('done.')
}

main()

How often does it reproduce? Is there a required condition?

Everytime script is run

What is the expected behavior?

I see "done." it appended the two files.

What do you see instead?

Nothing it silently crashes

Additional information

Here is a workaround with notes https://gist.github.com/webdevlocalhost/32822034a003d93f0452dff4d48e73c8

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateIssues and PRs that are duplicates of other issues or PRs.streamIssues and PRs related to the stream subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions