Skip to content

async.c:136: uv__async_io: Assertion `n == sizeof(val)' failed. #1171

Closed

Description

@rgagnon24

I am randomly seeing "node: ../deps/uv/src/unix/async.c:136: uv__async_io: Assertion `n == sizeof(val)' failed." on CentOS 7 with node 4.6.2

I researched the C file, and the code seems to not make sense.... https://github.com/libuv/libuv/blob/v1.x/src/unix/async.c#L103

There are 2 uses of the call wa->cb() that don't appear to be equivalent....

The "normal" one that happens at line 143:
wa->cb(loop, wa, n);

and the "special" one above it at line 138:
wa->cb(loop, wa, val);

The two different ways of calling wa->cb() don't seem to be doing the same thing. The "normal" one is using the size of the buffer in n, while the "special" one is sending what looks like part of a buffer copy.

I see the comment shows it is trying to fix a byte-alignment issue, but why is it copying the received buffer into val instead of the value of n ?

Activity

  1. cjihrig commented on Dec 16, 2016

    @cjihrig
    Contributor

    Do you happen to have code to reproduce the problem? Also, can you try with the latest version of Node?

  2. bnoordhuis commented on Dec 16, 2016

    @bnoordhuis
    Member

    On linux, the file descriptor is an eventfd. Reading from an eventfd should always return 8 bytes: it's a 64 bits counter, the number of writes since the last read.

    What value does n have when you hit the assert?

  3. rgagnon24 commented on Dec 16, 2016

    @rgagnon24
    Author

    This is the problem... I don't know where the code is dying since I am just running a node express app that does many different things... It runs daemonized, and randomly just stops running without anything in any log file.

    The only time I see the error is if I happen to still be in the console I started the process from when it dies.

    I don't know the value of "n" since that is INSIDE libuv

  4. rgagnon24 commented on Dec 16, 2016

    @rgagnon24
    Author

    For the alignment issue that code is trying to avoid, why isn't it copying n into val, so that the call wa->cb(loop, wa, val); would be equivalent to the one below it?

  5. bnoordhuis commented on Dec 16, 2016

    @bnoordhuis
    Member

    If you turn on core dumps (ulimit -c unlimited), you'll get a core dump that you can inspect in gdb.

    why isn't it copying n into val

    They're not the same thing. n is the number of bytes that are available for reading, val is the actual bytes.

  6. rgagnon24 commented on Dec 16, 2016

    @rgagnon24
    Author

    Correct... They are not the same thing... which is why I was wondering why the call to wa->cb() is using different things.

    I will setup to get core dumps and see what happens

  7. rgagnon24 commented on Dec 19, 2016

    @rgagnon24
    Author

    Ugh. File finally core dumped, but the core file might not be helpful. I'm a lot more familiar with C than the workings of gdb, but here is what I have at the moment:

    # gdb node core.27902
    ...
    Program terminated with signal 6, Aborted.
    #0  0x00007f27f80075f7 in raise () from /lib64/libc.so.6
    Missing separate debuginfos, use: debuginfo-install nodejs-4.6.2-1nodesource.el7.centos.x86_64
    (gdb) bt full
    #0  0x00007f27f80075f7 in raise () from /lib64/libc.so.6
    No symbol table info available.
    #1  0x00007f27f8008ce8 in abort () from /lib64/libc.so.6
    No symbol table info available.
    #2  0x00007f27f8000566 in __assert_fail_base () from /lib64/libc.so.6
    No symbol table info available.
    #3  0x00007f27f8000612 in __assert_fail () from /lib64/libc.so.6
    No symbol table info available.
    #4  0x0000000000ece71e in uv__async_io ()
    No symbol table info available.
    #5  0x0000000000edd8e8 in uv__io_poll ()
    No symbol table info available.
    #6  0x0000000000ecefb9 in uv_run ()
    No symbol table info available.
    #7  0x0000000000d73e50 in node::Start(int, char**) ()
    No symbol table info available.
    #8  0x00007f27f7ff3b15 in __libc_start_main () from /lib64/libc.so.6
    No symbol table info available.
    #9  0x0000000000728109 in _start ()
    No symbol table info available.
    (gdb) frame 4
    #4  0x0000000000ece71e in uv__async_io ()
    (gdb) list
    No symbol table is loaded.  Use the "file" command.
    
  8. bnoordhuis commented on Dec 19, 2016

    @bnoordhuis
    Member

    You will want to run that debuginfo-install command to obtain the debug symbols. Once you have them installed, select the uv__async_io frame with frame 4, then info locals.

  9. rgagnon24 commented on Dec 19, 2016

    @rgagnon24
    Author

    Thanks for the information....

    here's the result:

    (gdb) bt
    #0  0x00007f27f80075f7 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
    #1  0x00007f27f8008ce8 in __GI_abort () at abort.c:90
    #2  0x00007f27f8000566 in __assert_fail_base (fmt=0x7f27f8150ce8 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x11d1c11 "n == sizeof(val)", 
        file=file@entry=0x11d1bf5 "../deps/uv/src/unix/async.c", line=line@entry=136, function=function@entry=0x11d1c33 <__PRETTY_FUNCTION__.9544> "uv__async_io")
        at assert.c:92
    #3  0x00007f27f8000612 in __GI___assert_fail (assertion=assertion@entry=0x11d1c11 "n == sizeof(val)", file=file@entry=0x11d1bf5 "../deps/uv/src/unix/async.c", 
        line=line@entry=136, function=function@entry=0x11d1c33 <__PRETTY_FUNCTION__.9544> "uv__async_io") at assert.c:101
    #4  0x0000000000ece71e in uv__async_io (loop=0x18a0e00 <default_loop_struct>, w=0x18a0fc8 <default_loop_struct+456>, events=<optimized out>)
        at ../deps/uv/src/unix/async.c:136
    #5  0x0000000000edd8e8 in uv__io_poll (loop=loop@entry=0x18a0e00 <default_loop_struct>, timeout=0) at ../deps/uv/src/unix/linux-core.c:380
    #6  0x0000000000ecefb9 in uv_run (loop=0x18a0e00 <default_loop_struct>, mode=UV_RUN_ONCE) at ../deps/uv/src/unix/core.c:354
    #7  0x0000000000d73e50 in StartNodeInstance (arg=<synthetic pointer>, this=<optimized out>) at ../src/node.cc:4230
    #8  node::Start (argc=4, argv=0x305ebc0) at ../src/node.cc:4307
    #9  0x00007f27f7ff3b15 in __libc_start_main (main=0x727ea0 <main(int, char**)>, argc=4, ubp_av=0x7ffc8259bdf8, init=<optimized out>, fini=<optimized out>, 
        rtld_fini=<optimized out>, stack_end=0x7ffc8259bde8) at libc-start.c:274
    #10 0x0000000000728109 in _start ()
    
    

    and the content of the troublesome frame:

    (gdb) info locals
    val = <optimized out>
    wa = 0x18a0fc0 <default_loop_struct+448>
    buf = "\340\\7\003\000\000\000\000\000\353\026\005\227\237\266\203\260\261\n\003\000\000\000\000\060]8\003\000\000\000\000p\b\006\003\000\000\000\000`Q\n\003\000\000\000\000\060\263\a\003\000\000\000\000\004\000\000\000\000\000\000\000\220\205Y\202\374\177\000\000F\n\211\000\000\000\000\000\000\217\n\003\000\000\000\000\321\n\331Ó+\000\000\220\205Y\202\374\177\000\000\324f\212\000\000\000\000\000\200\206Y\202\374\177\000\000\260\261\n\003", '\000' <repeats 12 times>, "`Q\n\003\000\000\000\000\200\206Y\202\374\177\000\000Y\216\332\000\000\000\000\000\020\000\000\000\000\000\000\000\002", '\000' <repeats 23 times>, "p\b\006\003\000\000\000\000\370"...
    n = 0
    r = <optimized out>
    __PRETTY_FUNCTION__ = "uv__async_io"
    
    

    Interestingly enough, I was kind of expecting n to be a multiple of sizeof(val) instead of 0

  10. rgagnon24 commented on Dec 19, 2016

    @rgagnon24
    Author

    It looks to me as if the read() call is returning 0 for EOF, the #ifdef section is not built to expect that

  11. rgagnon24 commented on Dec 19, 2016

    @rgagnon24
    Author

    Probably should have also included the content of w and wa at the time:

    (gdb) p *wa
    $14 = {cb = 0xece540 <uv__async_event>, io_watcher = {cb = 0xece640 <uv__async_io>, pending_queue = {0x18a0fd0 <default_loop_struct+464>, 
          0x18a0fd0 <default_loop_struct+464>}, watcher_queue = {0x18a0fe0 <default_loop_struct+480>, 0x18a0fe0 <default_loop_struct+480>}, pevents = 1, events = 1, 
        fd = 8}, wfd = -1}
    (gdb) p *w
    $15 = {cb = 0xece640 <uv__async_io>, pending_queue = {0x18a0fd0 <default_loop_struct+464>, 0x18a0fd0 <default_loop_struct+464>}, watcher_queue = {
        0x18a0fe0 <default_loop_struct+480>, 0x18a0fe0 <default_loop_struct+480>}, pevents = 1, events = 1, fd = 8}
    
    
  12. rgagnon24 commented on Dec 20, 2016

    @rgagnon24
    Author

    Could this problem be a combination of the EOF on read() and how the "deasync" node module operates? I happen to be using deasync in places in the application, and note the deasync project also has an issue open similar to this title: abbr/deasync#34

  13. rgagnon24 commented on Dec 28, 2016

    @rgagnon24
    Author

    Any comments about my suggested patch above?

  14. rgagnon24 commented on Feb 1, 2017

    @rgagnon24
    Author

    Pull request #1214 created for review/comment

  15. GummyDonut commented on May 31, 2018

    @GummyDonut

    @rgagnon24 Sorry for bringing up this up again, but how did you go about debugging this? I am writing an express app and have encountered this issue as well.
    Note I have very weak knowledge of C and was wondering if you or someone could point me in the write direction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions