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

lib: fix issue throw null and throw undefined and also throw false crash in repl #16574

Closed
wants to merge 3 commits into from
Closed

Conversation

priyank-p
Copy link
Contributor

@priyank-p priyank-p commented Oct 28, 2017

The issue was that when it tries to check if err.message == 'Script execution interrupted.'
line 269 repl.js it throws error as e would be null or undefined. Now before it checks
the err.message it checks if err was null|undefined and id so returns err before checking
and exits,

# sample output repl
> throw null
Thrown: null 
> throw undefined 
Thrown: undefined

Fixes: #16545
Fixes: #16607

Checklist
Affected core subsystem(s)

repl

@nodejs-github-bot nodejs-github-bot added the repl Issues and PRs related to the REPL subsystem. label Oct 28, 2017
@priyank-p
Copy link
Contributor Author

make -j4 test
resulted in everything ok but this failure which i think is a current issue #16545

# output
make[1]: Leaving directory `/home/ubuntu/workspace/node'
/usr/bin/python2.7 tools/test.py --mode=release -J \
                async-hooks \
                default \
                addons addons-napi \
                doctool known_issues
=== release test-stringbytes-external-exceed-max ===                           
Path: addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max
Command: out/Release/node /home/ubuntu/workspace/node/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max.js
--- CRASHED (Signal: 9) ---
=== release test-stringbytes-external-exceed-max-by-1-binary ===               
Path: addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary
Command: out/Release/node /home/ubuntu/workspace/node/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary.js
--- CRASHED (Signal: 9) ---
=== release test-stringbytes-external-exceed-max-by-1-hex ===                  
Path: addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-hex
Command: out/Release/node /home/ubuntu/workspace/node/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-hex.js
--- CRASHED (Signal: 9) ---
=== release test-timers-block-eventloop ===                                    
Path: sequential/test-timers-block-eventloop
assert.js:45
  throw new errors.AssertionError({
  ^

AssertionError [ERR_ASSERTION]: eventloop blocked!
    at Timeout.mustNotCall [as _onTimeout] (/home/ubuntu/workspace/node/test/common/index.js:582:12)
    at ontimeout (timers.js:478:11)
    at tryOnTimeout (timers.js:302:5)
    at Timer.listOnTimeout (timers.js:262:5)
Command: out/Release/node /home/ubuntu/workspace/node/test/sequential/test-timers-block-eventloop.js
[12:02|% 100|+ 2038|-   4]: Done                                       
make: *** [test] Error 1

@mscdex
Copy link
Contributor

mscdex commented Oct 28, 2017

The target subsystem should be 'repl' instead of 'lib' in the commit message.

lib/repl.js Outdated
process.domain.emit('error', err);
process.domain.exit();
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

You can merge this with line 266-269 if you change the condition on line 260 to err && err.message === ... and line 275 to just if (process.domain) {.

Can you also add a regression test? Thanks.

Copy link
Member

Choose a reason for hiding this comment

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

test/parallel/test-repl-domain.js is probably the right place for it, although if you can fit it in one of the other test/parallel/test-repl-* tests, that's probably perfectly alright too.

Copy link
Contributor Author

@priyank-p priyank-p Oct 28, 2017

Choose a reason for hiding this comment

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

@bnoordhuis added regression test and fixed changes requested.

The issue was that when it tries to check if `err.message == 'Script execution interrupted.'`
line 269 repl.js it throws error as e would be `null` or `undefined`. Now before it checks
the err.message it checks if err was `null|undefined` and id so returns err before checking
and exits,

`
// sample output repl
> throw null
Thrown null
> throw undefined
Thrown undefined
`

Fixes: #16545
@joyeecheung
Copy link
Member

require('../common');

// This test makes sures that the repl does not
// crash or emit error when throwing `null|undefined`
Copy link
Member

Choose a reason for hiding this comment

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

makes sures -> makes sure

r.write('.exit\n');

let i = 0;
r.on('line', function replOutput(output) {
Copy link
Member

Choose a reason for hiding this comment

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

IMO new tests can accommodate arrow functions whenever possible.


let i = 0;
r.on('line', function replOutput(output) {
const testStatement = i === 0 ? 'null' : 'undefined';
Copy link
Member

Choose a reason for hiding this comment

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

While this mostly works, the eventemitter manifests pure asynchronous behavior and does not guarentee any order of listener invocation with respect to the order of the associated event, at least by specification. Is it possible to see if replOutput function can handle both the possibilities?

let i = 0;
r.on('line', function replOutput(output) {
const testStatement = i === 0 ? 'null' : 'undefined';
const expectedOutput = 'Thrown: ' + testStatement;
Copy link
Member

Choose a reason for hiding this comment

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

How about replacing this with template strings?

r.on('line', function replOutput(output) {
const testStatement = i === 0 ? 'null' : 'undefined';
const expectedOutput = 'Thrown: ' + testStatement;
const msg = 'repl did not throw ' + testStatement;
Copy link
Member

Choose a reason for hiding this comment

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

same as above

@priyank-p
Copy link
Contributor Author

@gireeshpunathil fixed all the changes requested. Also fixed issue that not all the time the asserstion would be made as r.on('line', func) is async so when the line r.write('exit\n') is executed the process exits with code 0.

All changes are amended to previous nit commit.

Copy link
Member

@gireeshpunathil gireeshpunathil left a comment

Choose a reason for hiding this comment

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

great, thank you!

let i = 0;
r.on('line', (statement) => {
const isThrowNull = statement.includes('null');
const assertFail = 'repl did not throw ';
Copy link
Member

Choose a reason for hiding this comment

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

Nit: can you please remove the trailing space? There is already one in the template string below.

const assertFail = 'repl did not throw ';
if (isThrowNull) {
// expecting output Thrown null
assert.deepStrictEqual(statement, 'Thrown null',
Copy link
Member

Choose a reason for hiding this comment

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

Nit: can you please use assert.strictEqual()?

return;
}

assert.deepStrictEqual(statement, 'Thrown undefined',
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

@priyank-p
Copy link
Contributor Author

@lpinca i added replaced the existing test as it does not throw error on previous node version 8.5.0. reason being that repl does not does not emit output to writer if there is and error. so no error checking but this should work.

@priyank-p priyank-p changed the title lib: fix issue throw null and throw undefined crash in repl lib: fix issue throw null and throw undefined and also throw false crash in repl Oct 30, 2017
@priyank-p
Copy link
Contributor Author

There is no way to test throw false through regression test as it will not throw error and it will not be passed through repl.writer.

Copy link
Member

@lance lance left a comment

Choose a reason for hiding this comment

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

CI looks good except for flakey raspberry pi builds

Copy link
Contributor

@Fishrock123 Fishrock123 left a comment

Choose a reason for hiding this comment

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

@lance
Copy link
Member

lance commented Oct 31, 2017

Landed in bb59d2b

@lance lance closed this Oct 31, 2017
lance pushed a commit that referenced this pull request Oct 31, 2017
When `throw undefined` or `throw null` is executed, the REPL crashes.
This change does a check for `null|undefined` before accessing an
error's properties to prevent crashing.

Fixes: #16545
Fixes: #16607

PR-URL: #16574
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Lance Ball <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
Qard pushed a commit to ayojs/ayo that referenced this pull request Nov 2, 2017
When `throw undefined` or `throw null` is executed, the REPL crashes.
This change does a check for `null|undefined` before accessing an
error's properties to prevent crashing.

Fixes: nodejs/node#16545
Fixes: nodejs/node#16607

PR-URL: nodejs/node#16574
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Lance Ball <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
Qard pushed a commit to ayojs/ayo that referenced this pull request Nov 2, 2017
When `throw undefined` or `throw null` is executed, the REPL crashes.
This change does a check for `null|undefined` before accessing an
error's properties to prevent crashing.

Fixes: nodejs/node#16545
Fixes: nodejs/node#16607

PR-URL: nodejs/node#16574
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Lance Ball <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
cjihrig pushed a commit to cjihrig/node that referenced this pull request Nov 6, 2017
When `throw undefined` or `throw null` is executed, the REPL crashes.
This change does a check for `null|undefined` before accessing an
error's properties to prevent crashing.

Fixes: nodejs#16545
Fixes: nodejs#16607

PR-URL: nodejs#16574
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Lance Ball <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
@cjihrig cjihrig mentioned this pull request Nov 6, 2017
@MylesBorins
Copy link
Contributor

This fix does not appear to fix the problem on v6.x

Would someone be willing to do a manual backport?

gibfahn pushed a commit that referenced this pull request Nov 14, 2017
When `throw undefined` or `throw null` is executed, the REPL crashes.
This change does a check for `null|undefined` before accessing an
error's properties to prevent crashing.

Fixes: #16545
Fixes: #16607

PR-URL: #16574
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Lance Ball <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
@gibfahn gibfahn mentioned this pull request Nov 21, 2017
addaleax pushed a commit to ayojs/ayo that referenced this pull request Dec 7, 2017
When `throw undefined` or `throw null` is executed, the REPL crashes.
This change does a check for `null|undefined` before accessing an
error's properties to prevent crashing.

Fixes: nodejs/node#16545
Fixes: nodejs/node#16607

PR-URL: nodejs/node#16574
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Lance Ball <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
@priyank-p priyank-p deleted the repl-issue branch January 2, 2018 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
repl Issues and PRs related to the REPL subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

throw false ignored in REPL throw null and throw undefined crash in repl