-
Notifications
You must be signed in to change notification settings - Fork 28.9k
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
a simple script to crash Node.js with an assertion failure: (loop->watchers[w->fd] == w) #3604
Comments
@pmq20 What Node version and which OS? I can't repro on Node v4.2.1 and OS X 10.10.5 |
@Fishrock123 I'm using Node.js v4.2.1 and Mac OS X 10.11 (15A284) |
@pmq20 My machine has a Quad-core 2.6ghz i7 -- perhaps the test isn't race-y enough? |
@Fishrock123 I have revised the script to loop on fd, could you try it again? |
Reproed. Thanks.
|
I'm not sure if this could be considered a bug. Libuv does not allow to watch the same file descriptors twice, and this is a manifestation of this behavior. Most of the bugs that I have seen that was triggering |
@indutny I just thought pure JS code without any addons should not cause C-level panic under any circumstance |
@pmq20 well, it probably should throw indeed. cc @bnoordhuis @saghul |
Ideally libuv itself should check if a fd is already being watched and scream with an error. Now, I remember this wasn't as straightforward as it sounds, but I'll take another look, since I might be remembering wrong... |
Weird. I am able to reproduce this problem only in REPL. |
I've this same crash when using node-serialport. Is there any way to avoid this ? |
@saghul is there a libuv issue for this yet? |
@Fishrock123 alas no. And it's not easy to write one (IIRC), that's why it hasn't been done yet. |
FWIW, this is still reproducible with node 7.2.1 (OSX). I run into this assertion occasionally when using a custom nwjs-app that streams serial data, but since it's not deterministic I attribute my specific problems to a race condition elsewhere (not node/uv). |
I have this issue in node v4l2camera module |
Got the same bug in a webinterface using socket.io and express with ejs. As far as I can tell, it happens when I try to login from a different machine using firefore, but not from my computer using Chrome. |
This hit me today, I did nothing but run some HTTP requests one of which ended in a timeout, and then this showed up. Is there a way to avoid this ? Node v9.11.1 |
there are 2 issues with the (original) test case:
Smallest code to reproduce the issue:
The fd # may not be 8 always, but in and around. In my MAC with a Node version it is 8, and in Linux it is 6. This fd is already opened and in use by Node, for signal watching. A new stream object is created with this fd as the data source. I believe we should ensure: assert(loop->watchers[w->fd] == NULL) while setting up a watcher too, to make the current assertion to be reasonable. Doing so does not help the test case, but catches faults much earlier. A standalone test case that does not involve arbitray fds in the picture: $ cat 3604.js var c = require('child_process')
var n = require('net')
if (process.argv[2] === 'c') {
var i = new n.Socket({fd: 0})
var o = new n.Socket({fd: 1})
i.on('data', (d) => {
console.log(d.toString())
})
} else {
var cp = c.spawn(process.execPath, [__filename, 'c'])
cp.stdout.pipe(process.stdout);
cp.stderr.pipe(process.stdout);
cp.stdin.write('hello!\n')
} $ node 3604
@nodejs/libuv |
@gireeshpunathil There's already an open libuv issue about that, libuv/libuv#1172. |
thanks @bnoordhuis - I missed that. |
Notable changes: - Building via cmake is now supported. PR-URL: libuv/libuv#1850 - Stricter checks have been added to prevent watching the same file descriptor multiple times. PR-URL: libuv/libuv#1851 Refs: nodejs#3604 - An IPC deadlock on Windows has been fixed. PR-URL: libuv/libuv#1843 Fixes: nodejs#9706 Fixes: nodejs#7657 - uv_fs_lchown() has been added. PR-URL: libuv/libuv#1826 Refs: nodejs#19868 - uv_fs_copyfile() sets errno on error. PR-URL: libuv/libuv#1881 Fixes: nodejs#21329 - uv_fs_fchmod() supports -A files on Windows. PR-URL: libuv/libuv#1819 Refs: nodejs#12803 PR-URL: nodejs#21466 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Notable changes: - Building via cmake is now supported. PR-URL: libuv/libuv#1850 - Stricter checks have been added to prevent watching the same file descriptor multiple times. PR-URL: libuv/libuv#1851 Refs: #3604 - An IPC deadlock on Windows has been fixed. PR-URL: libuv/libuv#1843 Fixes: #9706 Fixes: #7657 - uv_fs_lchown() has been added. PR-URL: libuv/libuv#1826 Refs: #19868 - uv_fs_copyfile() sets errno on error. PR-URL: libuv/libuv#1881 Fixes: #21329 - uv_fs_fchmod() supports -A files on Windows. PR-URL: libuv/libuv#1819 Refs: #12803 PR-URL: #21466 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
I am unable to recreate the crash in the current Node.js 10.9, 8.12, and master. Not exactly sure which commit fixed the issue. I'm unable to reproduce on the most recent version of 6 also. |
Closing. If someone is able to recreate this issue, on current versions, please weigh in and we can reopen. |
$ cat 3604.js var net = require('net')
var fd = 3;
while (fd<1000) {
try {
var stream = new net.Socket({
fd: fd,
readable: false,
writable: true
});
stream.on('error', function() {});
stream.write('might crash');
} catch(e) {console.log(e)}
fd += 1;
}
@jasnell - for the context, watching same fd twice now throws valid JS error instead of Though the underlying issue is not resolved, this mitigation looks good in the context of current libuv design, and hence I agree this issue can be closed (other than hand-crafted fd situations, under normal JS programming cases this do not show up). |
I also get this crash in Nodejs v8.11.3. |
Notable changes: - Building via cmake is now supported. PR-URL: libuv/libuv#1850 - Stricter checks have been added to prevent watching the same file descriptor multiple times. PR-URL: libuv/libuv#1851 Refs: nodejs#3604 - An IPC deadlock on Windows has been fixed. PR-URL: libuv/libuv#1843 Fixes: nodejs#9706 Fixes: nodejs#7657 - uv_fs_lchown() has been added. PR-URL: libuv/libuv#1826 Refs: nodejs#19868 - uv_fs_copyfile() sets errno on error. PR-URL: libuv/libuv#1881 Fixes: nodejs#21329 - uv_fs_fchmod() supports -A files on Windows. PR-URL: libuv/libuv#1819 Refs: nodejs#12803 PR-URL: nodejs#21466 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Notable changes: - Building via cmake is now supported. PR-URL: libuv/libuv#1850 - Stricter checks have been added to prevent watching the same file descriptor multiple times. PR-URL: libuv/libuv#1851 Refs: #3604 - An IPC deadlock on Windows has been fixed. PR-URL: libuv/libuv#1843 Fixes: #9706 Fixes: #7657 - uv_fs_lchown() has been added. PR-URL: libuv/libuv#1826 Refs: #19868 - uv_fs_copyfile() sets errno on error. PR-URL: libuv/libuv#1881 Fixes: #21329 - uv_fs_fchmod() supports -A files on Windows. PR-URL: libuv/libuv#1819 Refs: #12803 Backport-PR-URL: #24103 PR-URL: #21466 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This crash was reported several times in [1] [2] [3] [4], I also devised a simple script to reproduce the crash as below.
[1] joyent/libuv#838
[2] joyent/libuv#1348
[3] jeremycx/node-LDAP#33
[4] serialport/node-serialport#262
The text was updated successfully, but these errors were encountered: