-
Notifications
You must be signed in to change notification settings - Fork 35
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
Conversation
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.
Respond to close instead of exit events
Thanks @bripkens! Published to npm as 0.3.3. |
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'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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.