Skip to content

fix #129 install process listeners safely#130

Merged
silkentrance merged 1 commit intomasterfrom
gh-129
Nov 29, 2017
Merged

fix #129 install process listeners safely#130
silkentrance merged 1 commit intomasterfrom
gh-129

Conversation

@silkentrance
Copy link
Copy Markdown
Collaborator

@silkentrance silkentrance commented Jun 29, 2017

See #129

WIP
TODO: additional tests

@silkentrance silkentrance requested a review from raszi June 29, 2017 20:37
@silkentrance silkentrance force-pushed the gh-129 branch 3 times, most recently from 0ad4041 to 26f778b Compare July 4, 2017 19:23
@silkentrance silkentrance mentioned this pull request Jul 4, 2017
@silkentrance silkentrance force-pushed the gh-129 branch 9 times, most recently from 5f969f9 to b838d3a Compare July 6, 2017 19:58
lib/tmp.js Outdated

// we use this for determining which SIGINT handler we need to install
// TODO:is M$ so dim, win32 for win64 and future win128 platforms?
const isWindows = process.platform == 'win32';
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This is unused in this PR.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed

lib/tmp.js Outdated
if (_isUndefined(options)) {
return [{}, callback];
if (typeof options == 'function') {
result[0] = {};
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I prefer the early returns and the immutable values instead of this.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed

lib/tmp.js Outdated
/*
* Module dependencies.
*/
const tmpdir = require('os-tmpdir');
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Why was it necessary to rename the const?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed

lib/tmp.js Outdated

for (var i = 0, length = listeners.length; i < length; i++) {
var lstnr = listeners[i];
if ((lstnr.name == listener.name) || _is_legacy_listener(listener.name)) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

No need for the extra parens around the equality check.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed

lib/tmp.js Outdated
if (opts.template && !opts.template.match(TEMPLATE_PATTERN))
return cb(new Error('Invalid template provided'));

// FIXME:get rid of duplicate code
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please put a space after the FIXME keyword, like this:

// FIXME get rid of duplicate code

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed

@silkentrance silkentrance force-pushed the gh-129 branch 2 times, most recently from a8ec86d to d851283 Compare July 8, 2017 17:42
@silkentrance
Copy link
Copy Markdown
Collaborator Author

NOTE that this is still work in progress

@silkentrance silkentrance force-pushed the gh-129 branch 10 times, most recently from 99df905 to 7aff3ad Compare July 10, 2017 16:42
lib/tmp.js Outdated
}

return [options, callback];
return [options, callback];
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

There is an unnecessary whitespace at the end of the line.

Copy link
Copy Markdown
Collaborator Author

@silkentrance silkentrance Aug 16, 2017

Choose a reason for hiding this comment

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

fixed, found another one in line 571.

@silkentrance silkentrance force-pushed the gh-129 branch 3 times, most recently from b8bbc57 to 243cc12 Compare August 16, 2017 19:33
@silkentrance
Copy link
Copy Markdown
Collaborator Author

IMPORTANT tests are still missing!

@silkentrance silkentrance force-pushed the gh-129 branch 2 times, most recently from ac64a81 to 7c72786 Compare November 28, 2017 23:51
@silkentrance
Copy link
Copy Markdown
Collaborator Author

There seems to be an issue with the new tests. I will have to look into that.

@silkentrance silkentrance force-pushed the gh-129 branch 2 times, most recently from 6b9ffca to 5ea71f1 Compare November 29, 2017 22:27
@silkentrance
Copy link
Copy Markdown
Collaborator Author

silkentrance commented Nov 29, 2017

@raszi while the existing test case test/issue129-test and test/outband/issue129.js(on) does not completely encompass the behaviour of facebook/jest, which utilises sandboxes, I think that we can be safe in the assumption that tmp will register its handlers safely and not try to register handlers multiple times.

That being said, I dropped the uncaughtException handler completely. And while earlier versions of tmp will still install that handler, I think that we can be safe to assume that it does not matter, as it gets collected by the function that safely installs the exit handler, making use of _is_legacy_listener(). In fact, any uncaught exception handlers installed by tmp will be removed altogether, leaving only the legacy _exit handlers.

I tried to not be too smart about detecting whether it is a legacy handler installed by tmp, just limiting it to the handlers name and whether it includes a call to _garbageCollector();.

However, we will still have to notify interested third parties to update their dependencies accordingly, especially when they are using facebook/jest or some other framework that makes use of sandboxes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants