-
Notifications
You must be signed in to change notification settings - Fork 30k
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
events: fix TypeError in EventEmitter warning #9021
Conversation
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.
LGTM if CI is OK.
Nit: Would be great if you could rewrite the commit message to follow the commit message format requested in the CONTRIBUTING.md doc.
/cc @nodejs/testing At first I thought the test file where the test is put was probably not the right place, based on the test file name, but closer inspection makes me think it's actually OK. Second opinion welcome, though.
@jseagull I would add another test, similar to this one https://github.com/nodejs/node/blob/master/test/parallel/test-event-emitter-max-listeners-warning.js, to check that error message is the expected one. |
@lpinca |
e.setMaxListeners(1); | ||
|
||
process.on('warning', common.mustCall((warning) => { | ||
assert.ok(warning instanceof Error); |
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.
Can you add an assertion with something like this:
assert.ok(warning.message.includes('2 Symbol(symbol) listeners added.'));
LGTM with the commit message format fixed, @lpinca suggestion implemented and CI green. |
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.
LGTM
@@ -257,8 +257,9 @@ function _addListener(target, type, listener, prepend) { | |||
if (m && m > 0 && existing.length > m) { | |||
existing.warned = true; | |||
const w = new Error('Possible EventEmitter memory leak detected. ' + | |||
`${existing.length} ${type} listeners added. ` + | |||
'Use emitter.setMaxListeners() to increase limit'); | |||
`${existing.length} ${type.toString()} listeners ` + |
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 isn't safe since type
can currently be any type of value. So null.toString()
will fail for example. It will probably be better to just concatenate with an empty string.
EDIT: On second thought, we may have to just add logic before this to figure out how to create presentable output since Symbols cannot be implicitly converted. Perhaps something like this?:
var typeStr;
if (type && typeof type.toString === 'function')
typeStr = type.toString();
else
typeStr = '' + type;
const w = new Error('Possible EventEmitter memory leak detected. ' +
`${existing.length} ${typeStr} listeners ` +
// ...
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.
@mscdex isn't this a programmer error? type should be either a string or a symbol.
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.
@mscdex I change type.toString()
to String(type)
for safe reason
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.
@lpinca No, currently values like null
are allowed as types. I've actually used numbers before for the event name as part of a generic protocol parser.
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.
Gotcha.
For the commit message, maybe something like:
|
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.
LGTM. The ,test
in the commit message can be left out, ideally almost all code changes come with tests, so that can be assumed as an implied default :)
@@ -13,6 +13,14 @@ assert.ok(!e._events['default'].hasOwnProperty('warned')); | |||
e.on('default', function() {}); | |||
assert.ok(e._events['default'].warned); | |||
|
|||
// symbol | |||
var sym = Symbol('x'); |
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.
tiny nit: This can be const
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.
All variable in this file is defined with var, so I kept the style.
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.
We are in the process of migrating the code from var
to const
. It's not really practical to update a codebase this large in one pass, so we make the updates as we touch the code. Can you please add new code using const
.
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.
If you use const
and let
, you can also isolate the tests using curly braces. So:
{
const sym = Symbol('x');
e.setMaxListeners(1);
...
}
I took the liberty to update PR title. |
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.
LGTM
New CI: https://ci.nodejs.org/job/node-test-pull-request/4458/ |
Nit: Add a test for |
Allows Symbol to be converted to String so it can be included in the error. Fixes: nodejs#9003
Using 'Changelog to branch' strategy.
Cleaning workspace
> git rev-parse --verify HEAD # timeout=10
Resetting working tree
> git reset --hard # timeout=10
FATAL: java.io.EOFException
hudson.remoting.RequestAbortedException: java.io.EOFException
at hudson.remoting.Request.abort(Request.java:303)
at hudson.remoting.Channel.terminate(Channel.java:847)
at org.jenkinsci.remoting.nio.NioChannelHub$3.run(NioChannelHub.java:614)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at ......remote call to test-digitalocean-freebsd10-x64-1(Native Method)
at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1416)
at hudson.remoting.Request.call(Request.java:172)
at hudson.remoting.Channel.call(Channel.java:780)
at hudson.remoting.RemoteInvocationHandler.invoke(RemoteInvocationHandler.java:249)
at com.sun.proxy.$Proxy73.clean(Unknown Source)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl.clean(RemoteGitImpl.java:449)
at hudson.plugins.git.extensions.impl.CleanCheckout.onCheckoutCompleted(CleanCheckout.java:28)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1137)
at hudson.scm.SCM.checkout(SCM.java:485)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1269)
at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:607)
at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:529)
at hudson.model.Run.execute(Run.java:1738)
at hudson.matrix.MatrixRun.run(MatrixRun.java:146)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:410)
Caused by: java.io.EOFException
at org.jenkinsci.remoting.nio.NioChannelHub$3.run(NioChannelHub.java:614)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Run condition [Always] enabling perform for step [[Execute a set of scripts, Execute a set of scripts]]
ERROR: Step ?Publish TAP Results? failed: no workspace for node-test-commit-freebsd/nodes=freebsd10-64 #4743
Checking ^not ok
ERROR: Build step failed with exception
java.lang.NullPointerException
at hudson.plugins.textfinder.TextFinderPublisher.findText(TextFinderPublisher.java:101)
at hudson.plugins.textfinder.TextFinderPublisher.perform(TextFinderPublisher.java:74)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:782)
at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:723)
at hudson.model.Build$BuildExecution.post2(Build.java:185)
at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:668)
at hudson.model.Run.execute(Run.java:1763)
at hudson.matrix.MatrixRun.run(MatrixRun.java:146)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:410)
Build step 'Jenkins Text Finder' marked build as failure
Notifying upstream projects of job completion
Finished: FAILURE It seems this is not caused by the changed code. |
@Trott covered |
c133999
to
83c7a88
Compare
Allows Symbol to be converted to String so it can be included in the error. Fixes: #9003 PR-URL: #9021 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Landed in 254ab63 |
Allows Symbol to be converted to String so it can be included in the error. Fixes: #9003 PR-URL: #9021 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
should this be backported? If so it will need a PR for both v4.x and v6.x |
Allows Symbol to be converted to String so it can be included in the error. Conflicts: lib/events.js Fixes: #9003 Backport-PR-URL: #12459 PR-URL: #9021 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Allows Symbol to be converted to String so it can be included in the error. Conflicts: lib/events.js Fixes: #9003 Backport-PR-URL: #12459 PR-URL: #9021 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Allows Symbol to be converted to String so it can be included in the error. Conflicts: lib/events.js Fixes: nodejs#9003 Backport-PR-URL: nodejs/node#12459 PR-URL: nodejs/node#9021 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
make -j8 test
(UNIX), orvcbuild test nosign
(Windows) passes