Repository navigation
Node aborts when logging to stdout in JS called from C++ #3422
Copy link
Copy link
Closed
Labels
c++Issues and PRs that require attention from people who are familiar with C++.Issues and PRs that require attention from people who are familiar with C++.
Description
This is a weird one and I haven't yet found a simpler way to reproduce it, but it does reproduce every time. This does require a mysql/mariadb server though.
This is happening on Linux.
Steps:
npm install https://github.com/mscdex/node-mariasql/tarball/0cff1a10fc- Place the following code in a file (e.g.
bug.js) and execute it (node bug.js):
var Client = require('mariasql');
(new Client()).on('error',function(e) {
// Change `console.log(e);` here to `console.error(e);` or emit it entirely and no abort happens ...
console.log(e);
}).connect({
// Values here do not matter much, as long as a connection is made but auth is bad/wrong
host:'127.0.0.1',
user:'root',
password:'ffffffffff'
});Output:
{ [Error: Access denied for user 'root'@'localhost' (using password: YES)] code: 1045 }
node: ../deps/uv/src/unix/core.c:856: uv__io_stop: Assertion `loop->watchers[w->fd] == w' failed.
Aborted (core dumped)
Backtrace:
#0 0x00007ffff6bf6e37 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1 0x00007ffff6bf8528 in __GI_abort () at abort.c:89
#2 0x00007ffff6befce6 in __assert_fail_base (fmt=0x7ffff6d3fc08 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n",
assertion=assertion@entry=0x19adbbe "loop->watchers[w->fd] == w", file=file@entry=0x19ad960 "../deps/uv/src/unix/core.c", line=line@entry=856,
function=function@entry=0x19adc5f <__PRETTY_FUNCTION__.8772> "uv__io_stop") at assert.c:92
#3 0x00007ffff6befd92 in __GI___assert_fail (assertion=0x19adbbe "loop->watchers[w->fd] == w", file=0x19ad960 "../deps/uv/src/unix/core.c", line=856,
function=0x19adc5f <__PRETTY_FUNCTION__.8772> "uv__io_stop") at assert.c:101
#4 0x0000000001654c26 in uv__io_stop (loop=0x1edee80 <default_loop_struct>, w=0x1f32f58, events=4) at ../deps/uv/src/unix/core.c:856
#5 0x000000000166222c in uv_try_write (stream=0x1f32ed0, bufs=0x7fffffff5bf0, nbufs=1) at ../deps/uv/src/unix/stream.c:1470
#6 0x00000000015f366f in node::StreamWrap::DoTryWrite (this=0x1f32e40, bufs=0x7fffffff5b90, count=0x7fffffff5ba0) at ../src/stream_wrap.cc:307
#7 0x00000000015f09ef in node::StreamBase::WriteString<(node::encoding)1> (this=0x1f32e80, args=...) at ../src/stream_base.cc:289
#8 0x00000000015f4972 in node::StreamBase::JSMethod<node::StreamWrap, &node::StreamBase::WriteString<(node::encoding)1> > (args=...)
at ../src/stream_base-inl.h:100
#9 0x0000000000db29b2 in v8::internal::FunctionCallbackArguments::Call (this=0x7fffffff9de0,
f=0x15f48da <node::StreamBase::JSMethod<node::StreamWrap, &(int node::StreamBase::WriteString<(node::encoding)1>(v8::FunctionCallbackInfo<v8::Value> const&))>(v8::FunctionCallbackInfo<v8::Value> const&)>) at ../deps/v8/src/arguments.cc:33
#10 0x0000000000e06408 in v8::internal::HandleApiCallHelper<false> (isolate=0x1ee26b0, args=...) at ../deps/v8/src/builtins.cc:1092
#11 0x0000000000dffdd5 in v8::internal::Builtin_Impl_HandleApiCall (args=..., isolate=0x1ee26b0) at ../deps/v8/src/builtins.cc:1115
#12 0x0000000000dffd26 in v8::internal::Builtin_HandleApiCall (args_length=4, args_object=0x7fffffff9f80, isolate=0x1ee26b0) at ../deps/v8/src/builtins.cc:1111
I should also note that the abort doesn't happen when the problematic code is ran either in the REPL or via node -pe "...".
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
c++Issues and PRs that require attention from people who are familiar with C++.Issues and PRs that require attention from people who are familiar with C++.
Activity
bnoordhuis commentedon Oct 18, 2015
/cc @indutny
indutny commentedon Oct 18, 2015
Can't reproduce it on OS X. Going to build it on linux.
indutny commentedon Oct 18, 2015
@mscdex I get different assertion in binding when running it in Debug mode:
Could it be that the binding is faulty by itself?
indutny commentedon Oct 18, 2015
Yeah, it seems to be passing bad fd for me:
This is where
cb_pollis invoked from.mscdex commentedon Oct 18, 2015
@indutny Right, that may be the original bug I was trying to find, but I am still getting the other backtrace. I cannot for the life of me get the backtrace you are seeing.. :-(
I tried both v4.2.1 and master. FWIW it's on Ubuntu 14.10.
indutny commentedon Oct 18, 2015
@mscdex may I ask you to try bisecting node to find the commit that may have caused it?
mscdex commentedon Oct 18, 2015
Ok, git bisect is pointing to 1d0e5210a, which is when libuv was updated from 1.6.1 to 1.7.3.
indutny commentedon Oct 18, 2015
cc @saghul
mscdex commentedon Oct 18, 2015
Bisected the libuv upgrade and it looks like libuv/libuv@60fca01705 is the breaking commit there.
bnoordhuis commentedon Oct 19, 2015
I'd start with the assumption that this is a node.js bug that gets flushed out by a libuv change.
src/tty_wrap.ccdoesn't check the return value ofuv_tty_init().indutny commentedon Oct 19, 2015
Most likely this is the case, @bnoordhuis . @mscdex what happens if you will run it like this
valgrind node bug.js? I expect there to be an access to uninitialized variables.mscdex commentedon Oct 19, 2015
@indutny I'm not seeing that in the valgrind output.
bnoordhuis commentedon Oct 19, 2015
Am I right this patch hits the CHECK?
mscdex commentedon Oct 19, 2015
@bnoordhuis It's passing the check. I added a debug statement and
uv_tty_init()is indeed returning 0 (twice).indutny commentedon Oct 19, 2015
@mscdex are you sure about libuv/libuv@60fca01705 ?
mscdex commentedon Oct 19, 2015
@indutny Pretty sure, yes. If I check out at the parent commit no abort happens.
indutny commentedon Oct 19, 2015
@mscdex just to make sure I understand it correctly, you are reverting just that change in
deps/uvand it is starting to work.mscdex commentedon Oct 19, 2015
@indutny Yes. With libuv/libuv@60fca01 it aborts. With the parent commit libuv/libuv@c1fe25f654 it doesn't abort.
indutny commentedon Oct 19, 2015
@mscdex may I ask you to reproduce it on debug build of node? If it will still crash, may I ask you to print:
p *win the frame ofuv__io_stop(you can switch frames by typingf <FRAME-NUMBER>in gdb)mscdex commentedon Oct 19, 2015
@indutny
I believe fd 9 is the socket fd for the database connection.
indutny commentedon Oct 19, 2015
@mscdex ok, now it is time for a serious action :) Let's add:
Before https://github.com/nodejs/node/blob/master/lib/net.js#L644
mscdex commentedon Oct 19, 2015
Nothing new is displayed with that change.
indutny commentedon Oct 19, 2015
Ok, this is bad :(
indutny commentedon Oct 19, 2015
Let's add
v8::Message::PrintCurrentStackTrace(v8::Isolate::GetCurrent(), stderr)before https://github.com/nodejs/node/blob/master/src/stream_wrap.cc#L307mscdex commentedon Oct 19, 2015
With that added I get:
Line 404 in Client.js is just where I
emit('error', err).indutny commentedon Oct 19, 2015
Hm... this is very very strange. It looks like the
uv_tty_tis overwritten by someone.indutny commentedon Oct 19, 2015
I see no other choice, but to you memory breakpoints in gdb. Hope you don't mind helping me (sorry for lots of instructions):
b uv_tty_initrwatch &tty->fd, and also please record somewhere the pointer value ofttyand the numberfdstreaminuv_try_write.Thanks!
indutny commentedon Oct 19, 2015
As discussed on IRC, it does seem to be a mariadb binding bug, not a node.js/libuv bug . @mscdex feel free to reopen the issue if it will turn out to be something else.