Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respond to close instead of exit events #9

Merged
merged 1 commit into from
Mar 17, 2014
Merged

Respond to close instead of exit events #9

merged 1 commit into from
Mar 17, 2014

Conversation

bripkens
Copy link
Contributor

I observed a race condition when observing the 'exit' instead of
the 'close' event. Sometimes encryption would work, sometimes it
wouldn't. Debugging showed that the 'exit' event is sometimes
called before a 'data' event arrives.

The Node.js documentation actually states such behavior:

Event: 'exit'
Note that the child process stdio streams might still be open.
http://nodejs.org/api/child_process.html#child_process_event_exit

Event: 'close'
This event is emitted when the stdio streams of a child process
have all terminated. This is distinct from 'exit', since multiple
processes might share the same stdio streams.
http://nodejs.org/api/child_process.html#child_process_event_close

This commit switches from the 'exit' to 'close' events.

I observed a race condition when observing the 'exit' instead of
the 'close' event. Sometimes encryption would work, sometimes it
wouldn't. Debugging showed that the 'exit' event is sometimes
called before a 'data' event arrives.

The Node.js documentation actually states such behavior:

  Event: 'exit'
  Note that the child process stdio streams might still be open.
  http://nodejs.org/api/child_process.html#child_process_event_exit

  Event: 'close'
  This event is emitted when the stdio streams of a child process
  have all terminated. This is distinct from 'exit', since multiple
  processes might share the same stdio streams.
  http://nodejs.org/api/child_process.html#child_process_event_close

This commit switches from the 'exit' to 'close' events.
drudge added a commit that referenced this pull request Mar 17, 2014
Respond to close instead of exit events
@drudge drudge merged commit 0325ef6 into drudge:master Mar 17, 2014
@drudge
Copy link
Owner

drudge commented Mar 17, 2014

Thanks @bripkens! Published to npm as 0.3.3.

@bripkens
Copy link
Contributor Author

Wow, thank you very much @drudge for merging and releasing this so fast!

@@ -124,7 +124,7 @@ var GPG = {
fn.call(null, null, buffer);
});

gpg.stdin.end(str);
gpg.stdin.end(str, 'utf8');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this a necessary change? Why only in this spot? There are other places where stdin.end() is called without this change.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bripkens see my comment above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't have been necessary. The only intention was to change the event that is being listened to.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will revert that then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants