max-mapper / max-mapper/multiplex

Is there a clean way to close a stream between two muxes?

Open
#30 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
143
Forks
25
PR merge metrics
No merged PRs in 30d

Description

``` node
var mux1 = multiplex(function () {

});

var mux2 = multiplex(function (stream) {
stream.on('error', function (err) {
console.log("Got error on mux2 - " + err);
});
stream.on('finish', function () {
console.log("We are finish in mux2");
});
stream.on('close', function () {
console.log("We are closed in mux2");
});
});

mux1.pipe(mux2).pipe(mux1);

var stream = mux1.createStream();
stream.on('finish', function () {
console.log("We are finish");
});
stream.on('close', function () {
console.log("We are closed");
});
stream.end();
```

If I run that code then all I get out is "We are finish". In other words, there doesn't seem to be anyway for mux2 to find out that the stream it's connected to on mux1 has ended. That seems surprising to me.

Now if I change stream.end() to stream.destroy() then I will get an error in mux2 followed by a close. I suppose that works but it's not terribly gentle. I would have expected that there is some 'clean' way to close a stream.

What am I missing? Thanks!

Contributor guide

Open the contributing guide

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

Start with the supplied mux1.pipe(mux2).pipe(mux1) reproduction and trace createStream(), end(), destroy(), and the finish, close, and error events in the multiplex implementation. Done means establishing and testing the supported clean stream-closing behavior between the two muxes.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.