镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Check failed: result.second #32463

Description

@richardlau

unrelated failure in multiple different PRs?

test.node-api/test_buffer/test

#
# Fatal error in , line 0
# Check failed: result.second.
#
#
#
#FailureMessage Object: 0x3fffcd8ab3d0
 1: 0x106f06f4  [out/Release/node]
 2: 0x11b83bec V8_Fatal(char const*, ...) [out/Release/node]
 3: 0x10c4685c v8::internal::GlobalBackingStoreRegistry::Register(std::shared_ptr<v8::internal::BackingStore>) [out/Release/node]
 4: 0x1089f2c0 v8::ArrayBuffer::GetBackingStore() [out/Release/node]
 5: 0x106385f8  [out/Release/node]
 6: 0x108fb184  [out/Release/node]
 7: 0x108fd324 v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [out/Release/node]
 8: 0x11377680  [out/Release/node]

Not sure why you pinged build here as that's a code problem (failing check). From the stack trace and previously (#31061) that check is to with arraybuffers and backing stores. If it's occurring in multiple PR's that would suggest something has landed on master that has regressed.

Originally posted by @richardlau in #32414 (comment)

Activity

  1. richardlau commented on Mar 24, 2020

    @richardlau
    MemberAuthor

    Pulling this out into a separate issue for visibility.

    @ronag do you have links to the failing runs? If we can isolate when it started happening it might help work out what caused it.

  2. ronag commented on Mar 24, 2020

    @ronag
    Member

    https://ci.nodejs.org/job/node-test-commit-plinux/31722/

    Might be flaky. I did see it in another PR as well but can't find it at the moment.

  3. davedoesdev commented on May 6, 2020

    @davedoesdev
    Contributor

    I'm seeing this in Node 14.1.0 if I create two Buffers (using Napi::Buffer<uint8_t>::New) pointing to the same memory (stack trace below). I'm guessing this trips the CHECK in backing-store.cc because the address is already in map_.
    Allocating two external buffers pointing to the same address used to work. Is the change in behaviour expected?

    #
    # Fatal error in , line 0
    # Check failed: result.second.
    #
    #
    #
    #FailureMessage Object: 0x7ffc13226770
     1: 0x55f12e563285  [/home/david/node/out/Release/node]
     2: 0x55f12f57d916 V8_Fatal(char const*, ...) [/home/david/node/out/Release/node]
     3: 0x55f12e99b485 v8::internal::GlobalBackingStoreRegistry::Register(std::shared_ptr<v8::internal::BackingStore>) [/home/david/node/out/Release/node]
     4: 0x55f12e6bd967 v8::ArrayBuffer::GetBackingStore() [/home/david/node/out/Release/node]
     5: 0x55f12e4c4cbb node::Buffer::New(node::Environment*, char*, unsigned long, void (*)(char*, void*), void*) [/home/david/node/out/Release/node]
     6: 0x55f12e4c4fa2 node::Buffer::New(v8::Isolate*, char*, unsigned long, void (*)(char*, void*), void*) [/home/david/node/out/Release/node]
     7: 0x55f12e4b743e napi_create_external_buffer [/home/david/node/out/Release/node]
     8: 0x7f61c8d4e062 Napi::Buffer<unsigned char>::New(napi_env__*, unsigned char*, unsigned long) [/home/david/shared-memory-disruptor/build/Debug/disruptor.node]
     9: 0x7f61c8d4d2be Napi::Buffer<unsigned char> Disruptor::ProduceClaimSync<Napi::Buffer>(Napi::Env const&, bool, unsigned long&, unsigned long&) [/home/david/shared-memory-disruptor/build/Debug/disruptor.node]
    10: 0x7f61c8d4565e Disruptor::ProduceClaim(Napi::CallbackInfo const&) [/home/david/shared-memory-disruptor/build/Debug/disruptor.node]
    11: 0x7f61c8d4f49d Napi::ObjectWrap<Disruptor>::InstanceMethodCallbackWrapper(napi_env__*, napi_callback_info__*)::{lambda()#1}::operator()() const [/home/david/shared-memory-disruptor/build/Debug/disruptor.node]
    12: 0x7f61c8d50c02 napi_value__* Napi::details::WrapCallback<Napi::ObjectWrap<Disruptor>::InstanceMethodCallbackWrapper(napi_env__*, napi_callback_info__*)::{lambda()#1}>(Napi::ObjectWrap<Disruptor>::InstanceMethodCallbackWrapper(napi_env__*, napi_callback_info__*)::{lambda()#1}) [/home/david/shared-memory-disruptor/build/Debug/disruptor.node]
    13: 0x7f61c8d4f535 Napi::ObjectWrap<Disruptor>::InstanceMethodCallbackWrapper(napi_env__*, napi_callback_info__*) [/home/david/shared-memory-disruptor/build/Debug/disruptor.node]
    14: 0x55f12e49a9d8  [/home/david/node/out/Release/node]
    15: 0x55f12e6f6d3f v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) [/home/david/node/out/Release/node]
    16: 0x55f12e6f7100  [/home/david/node/out/Release/node]
    17: 0x55f12e6f799a  [/home/david/node/out/Release/node]
    18: 0x55f12e6f824a v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [/home/david/node/out/Release/node]
    19: 0x55f12ef766b9  [/home/david/node/out/Release/node]
    
  4. davedoesdev commented on May 6, 2020

    @davedoesdev
    Contributor

    I guess this change is intended: https://monorail-prod.appspot.com/p/v8/issues/detail?id=9908

    I'll try to work around it in my addons.

  5. lovell commented on May 6, 2020

    @lovell
    Contributor

    Here are a couple of downstream issues from native modules that have been impacted by this:

    (Anecdotally I've heard https://github.com/grpc/grpc-node is also affected, but the only issue I can find that mentions it is pulumi/pulumi#4258 (comment) .)

    Suggestions for a straightforward fix or workaround for this breaking change would be greatly appreciated.

  6. strigona-worksight commented on May 6, 2020

    @strigona-worksight

    I have experienced issues with grpc-node as well in some early tests of node 14. I haven't circled back to gather enough info to submit an issue to the project.

  7. jasnell commented on May 6, 2020

    @jasnell
    Member
  8. davedoesdev commented on May 6, 2020

    @davedoesdev
    Contributor

    My addon has a fixed memory range so I'm able to work around this issue by making a single buffer and then calling Buffer#slice when I need to return a view onto it.
    Wouldn't work for addons which dynamically allocate memory though - I guess you could keep track of what you've allocated previously and use finalizers to determine when and when not to return the same object.

  9. chjj commented on May 8, 2020

    @chjj
    Contributor

    I'm having serious issues with this. I spent a while trying to debug it and I can't seem to figure it out. I've audited my code thoroughly and concluded that it does not pass live duplicate pointers into napi_create_external_buffer. I've also valgrinded it to ensure nothing funky is happening memory-wise.

    From what I can guess this is happening:

    1. Addon code allocates pointer P via malloc.
    2. P is passed into napi_create_external_buffer with a finalization callback which calls free(P). P is inserted into v8's global array buffer table for tracking.
    3. The finalization callback is executed on GC. P is freed and returned to the allocator. P is not yet removed from v8's global array buffer table.
    4. Addon code attempts to allocate memory once again. The allocator returns P, as it is now available.
    5. P is passed into napi_create_external_buffer. P still has not been removed from the v8 global array buffer table.
    6. The world ends with Check failed: result.second.

    Step 3 seems to be the issue (again, this is just my guess at what is happening). It's been difficult trying to isolate this as it appears to be a "now you see it, now you don't" type of issue. I've come up with an offensively slow workaround. I don't consider it acceptable performance-wise.

  10. addaleax commented on May 8, 2020

    @addaleax
    Member

    @chjj Yeah, we’ve been having a lot of trouble with this, too. This isn’t quite trivial to fix, because the API contracts for napi_create_external_buffer and the V8 BackingStore aren’t the same – you can’t run JS from the BackingStore deleter callback or necessarily even be sure on which thread it runs, but you can do that from the Node.js/N-API Buffer free callback.

    I’ll try to change the behavior here by making the Buffer free callback only fire once the BackingStore deleter runs, by posting a task back to the JS thread, but that’s not necessarily trivial either.

    (It’s unfortunate that we have a Buffer API in N-API at all, tbh. But that’s a mistake we can’t undo now.)

  11. chjj commented on May 8, 2020

    @chjj
    Contributor

    @addaleax, thanks for the response.

    I’ll try to change the behavior here by making the Buffer free callback only fire once the BackingStore deleter runs, by posting a task back to the JS thread, but that’s not necessarily trivial either.

    I see. Now that I'm understanding the issue more, I suppose the alternative would be to allow the programmer to pass two finalize callbacks: one for JS stuff, one for non-JS stuff which would execute atomically with the BackingStore deletion. That seems pretty ugly though and probably not possible to implement at this point.

    (It’s unfortunate that we have a Buffer API in N-API at all, tbh. But that’s a mistake we can’t undo now.)

    Would napi_create_external_arraybuffer not have this issue? Based on what you said above, I assumed it would.

    I'm going through my code now and considering how to rewrite all of this.

  12. addaleax commented on May 8, 2020

    @addaleax
    Member

    (It’s unfortunate that we have a Buffer API in N-API at all, tbh. But that’s a mistake we can’t undo now.)

    Would napi_create_external_arraybuffer not have this issue? Based on what you said above, I assumed it would.

    It does, unfortunately – for the same reason as the Buffer variant, its API contract precedes the V8 changes here. I’ll try to implement the solution from above, and see how far I’ll get with that.

  13. added
    bufferIssues and PRs related to the buffer subsystem.
    flaky-testIssues and PRs involving tests that fail intermittently in CI.
    node-apiIssues and PRs related to Node-API.
    on May 9, 2020
  14. 9 remaining items

  15. robertying commented on Nov 18, 2020

    @robertying

    The latest v14.15.0 still produces the same error. I'm doing simple buffer construction without "pointing two buffers to the same native address", and still get the error.

    The code roughly looks like this:

    color_image_data = (uint8_t *)malloc(data_length);
    memcpy(color_image_data, image_data_from_device, data_length);
    
    Napi::Buffer<uint8_t> color_image_buffer = Napi::Buffer<uint8_t>::New(env, color_image_data, data_length);

    I feel like this is what @chjj talked in #32463 (comment).


    Edit

    I finally figured out my problem was that image_data_from_device is probably already freed. Since I'm doing Napi::ThreadSafeFunction inside a loop, image_data_from_device is very likely to have been destructed when accessed inside the thread. Napi::Buffer may have been repeatedly initialized using the same nonsense pointer and hence the error. So it is indeed "pointing two buffers to the same native address".

  16. Brooooooklyn commented on Feb 16, 2022

    @Brooooooklyn

    @addaleax should we reopen it since it doesn't actually be fixed.

  17. addaleax commented on Feb 16, 2022

    @addaleax
    Member

    @Brooooooklyn Can you provide more context than this?

  18. schmod commented on May 26, 2022

    @schmod

    We're seeing this on Node 16.15.0 while running tests with Ava.

  19. Pablodotjs commented on Jun 16, 2022

    @Pablodotjs

    Getting this in Node v16.14.0 several times

  20. Ram4GB commented on Jun 29, 2022

    @Ram4GB

    I got same issue in Node v16.15.1 when I run tests with Vitest.

    # Fatal error in , line 0
    # Check failed: result.second.
    #
    #
    #
    #FailureMessage Object: 0000002046CFB340
     1: 00007FF7F1B879CF v8::internal::CodeObjectRegistry::~CodeObjectRegistry+114207
     2: 00007FF7F1AA3E9F std::basic_ostream<char,std::char_traits<char> >::operator<<+65103
     3: 00007FF7F27826C2 V8_Fatal+162
     4: 00007FF7F21EDA3D v8::internal::BackingStore::Reallocate+637
     5: 00007FF7F24371B9 v8::ArrayBuffer::GetBackingStore+137
     6: 00007FF7F1B367EA node::Buffer::Data+58
     7: 00007FF7F1B0AC5C DSA_meth_get_flags+19404
     8: 00007FF7F2405BC6 v8::internal::Builtins::code_handle+172790
     9: 00007FF7F24057B9 v8::internal::Builtins::code_handle+171753
    10: 00007FF7F2405A7C v8::internal::Builtins::code_handle+172460
    11: 00007FF7F24058E0 v8::internal::Builtins::code_handle+172048
    12: 00007FF7F24D8FE1 v8::internal::SetupIsolateDelegate::SetupHeap+494673
    13: 000001DFF0D54323
    
  21. bnoordhuis commented on Jun 29, 2022

    @bnoordhuis
    Member

    @Ram4GB Can you open a new issue and link back to this one? It's not clear whether this is in fact the same issue or just the same error message.

    By the way, the stack trace is bogus (common problem on Windows.) It'd be helpful if you could test on Linux or macOS, where the stack trace is reliable.

  22. mpowell90 commented on Jun 29, 2022

    @mpowell90

    @bnoordhuis not sure if this helps but rolling back to node v16.13.2 has stopped these intermittent fatal errors on my system (MacBook Pro M1).

  23. tony19 commented on Aug 10, 2022

    @tony19
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

    addonsIssues and PRs related to native addons.bufferIssues and PRs related to the buffer subsystem.flaky-testIssues and PRs involving tests that fail intermittently in CI.node-apiIssues and PRs related to Node-API.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions