pinojs / pinojs/thread-stream

TransformStream does not close

Open
#36 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
261
Forks
31
Avg merge
2d 9h
Merged PRs (30d)
4

Description

When using this module within a TranformStream, it leads to this error:

/Users/mspigolon/workspace/thread-stream/index.js:278
        throw new Error('end() took too long (10s)')
        ^

Error: end() took too long (10s)
    at ThreadStream.end (/Users/mspigolon/workspace/thread-stream/index.js:278:15)
// worker.js
const { Transform } = require('stream');

async function run (opts) {
  const myTransform = new Transform({
    autoDestroy: true,
    transform(chunk, encoding, callback) {
      console.log(chunk.toString());
      callback(null)
    }
  });
  return myTransform
}

module.exports = run

// ===========================
// index.js (from README)
'use strict'

const ThreadStream = require('./index')
const { join } = require('path')

const stream = new ThreadStream({
  filename: join(__dirname, 'worker.js'),
  workerData: { dest: './qwe.sss'},
  workerOpts: {}, // Other options to be passed to Worker
  sync: false, // default
})

stream.write('hello')

// Asynchronous flushing
stream.flush(function () {
  stream.write(' ')
  stream.write('world')

  // Synchronous flushing
  stream.flushSync()
  stream.end()
})

Adding the statement:

myTransform.end = myTransform.destroy

solve the issue, but I'm not sure it is the right path to solve because it mix the readable stream interface withing the writable stream one.
It seems the writer stream end correctly, but the reader is still alive.

The myTransform does not emit any events (close, finish etc..)

I tried Node.js v16 and 14 and I get the same results.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with the Transform in worker.js and the README example in index.js, then inspect thread-stream/index.js around line 278. Check the Transform's writable and readable lifecycle and its close, finish, and related events. Done means stream.end() completes without the 10-second timeout and the Transform shuts down as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
backend, stream-processing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.