-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Conversation
# 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 |
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; | ||
} |
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.
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.
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.
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.
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.
@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
require('../common'); | ||
|
||
// This test makes sures that the repl does not | ||
// crash or emit error when throwing `null|undefined` |
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.
makes sures -> makes sure
r.write('.exit\n'); | ||
|
||
let i = 0; | ||
r.on('line', function replOutput(output) { |
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.
IMO new tests can accommodate arrow functions whenever possible.
|
||
let i = 0; | ||
r.on('line', function replOutput(output) { | ||
const testStatement = i === 0 ? 'null' : 'undefined'; |
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.
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; |
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.
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; |
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.
same as above
@gireeshpunathil fixed all the changes requested. Also fixed issue that not all the time the asserstion would be made as All changes are amended to previous nit commit. |
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.
great, thank you!
let i = 0; | ||
r.on('line', (statement) => { | ||
const isThrowNull = statement.includes('null'); | ||
const assertFail = 'repl did not throw '; |
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.
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', |
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.
Nit: can you please use assert.strictEqual()
?
return; | ||
} | ||
|
||
assert.deepStrictEqual(statement, 'Thrown undefined', |
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.
Ditto.
@lpinca i added replaced the existing test as it does not throw error on previous node version |
throw null
and throw undefined
crash in replthrow null
and throw undefined
and also throw false
crash in repl
There is no way to test |
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.
CI looks good except for flakey raspberry pi builds
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.
Landed in bb59d2b |
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]>
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]>
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]>
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]>
This fix does not appear to fix the problem on v6.x Would someone be willing to do a manual backport? |
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]>
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]>
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
orundefined
. Now before it checksthe err.message it checks if err was
null|undefined
and id so returns err before checkingand exits,
Fixes: #16545
Fixes: #16607
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesFor make -j4 test
make error 1 Flaky test-timers-block-eventloop
Flaky test-timers-block-eventloop #16310commit message follows commit guidelines
Affected core subsystem(s)
repl