substack/comandante — pull request #2 by parshap (2013-07-31 05:13:13+00:00)
Title: Close event is triggered twice

I ran into an issue where the duplex stream returned by comandante emits two "close" events.

I created a test to reproduce this, and oddly even though the "close" event callback is called twice every time the code is run, tap seems to only report an error about 50% of the time. This non-deterministic behavior from tap is very odd, so you may need to run the test multiple times to see the error.

I believe the problem is that the are two sources emitting a "close" event:

1. The duplexer module proxies the "close" event from the child process's stdout read stream (see [duplexer/index.js#L27](https://github.com/Raynos/duplexer/blob/master/index.js#L27))
2. The child process's "close" event is proxied to the duplex stream by comandante (see [comandante/index.js#L36](https://github.com/parshap/comandante/blob/master/index.js#L36))

We want the "close" event from the child process object (2) not the one from the child process's stdout stream (1). I am not sure if there is a way to prevent duplexer from proxying the close event.

This pull request only includes a test to recreate this issue, not a fix.