Skip to content

Unref a socket raise v8 error #38707

Description

@niyan-ly
  • 15.14.0:
  • Linux:
  • Debian:

What steps will reproduce the bug?

const request = https.get('https://www.google.com', res => {

});

request.on('socket', socket => {
  socket.unref();
})

How often does it reproduce? Is there a required condition?

every time in Node.js 15.x and above

What is the expected behavior?

the process should exit gracefully

What do you see instead?

FATAL ERROR: v8::HandleScope::CreateHandle() Cannot create a handle without a HandleScope
 1: 0xa89e60 node::Abort() [node]
 2: 0x9ade29 node::FatalError(char const*, char const*) [node]
 3: 0xc7555a v8::Utils::ReportApiFailure(char const*, char const*) [node]
 4: 0xdfdde2 v8::internal::HandleScope::Extend(v8::internal::Isolate*) [node]
 5: 0xe10b7c v8::internal::FactoryBase<v8::internal::Factory>::NewRawOneByteString(int, v8::internal::AllocationType) [node]
 6: 0xe22b8e v8::internal::Factory::NewStringFromOneByte(v8::internal::Vector<unsigned char const> const&, v8::internal::AllocationType) [node]
 7: 0xc8cf72 v8::String::NewFromOneByte(v8::Isolate*, unsigned char const*, v8::NewStringType, int) [node]
 8: 0xc3a317 node::crypto::TLSWrap::InvokeQueued(int, char const*) [node]
 9: 0xc3a422  [node]
10: 0xc3a5e4 node::crypto::TLSWrap::~TLSWrap() [node]
11: 0xc3a751 node::crypto::TLSWrap::~TLSWrap() [node]
12: 0xa20c5b node::Environment::RunCleanup() [node]
13: 0x9d670c node::FreeEnvironment(node::Environment*) [node]
14: 0xacb25f node::NodeMainInstance::Run(node::EnvSerializeInfo const*) [node]
15: 0xa51d7a node::Start(int, char**) [node]
16: 0x7f6d63b5e09b __libc_start_main [/lib/x86_64-linux-gnu/libc.so.6]
17: 0x9d072c  [node]
Aborted (core dumped)

Activity

  1. added
    confirmed-bugIssues and PRs for confirmed bugs.
    tlsIssues and PRs related to the tls subsystem.
    on May 17, 2021
  2. targos commented on May 17, 2021

    @targos
    Member

    /cc @nodejs/net
    I can reproduce with Node.js 16.1.0

  3. targos commented on May 17, 2021

    @targos
    Member

    Debug backtrace on 75340f3:

    #0  0x00007ffff6cf683f in raise () from /lib64/libc.so.6
    #1  0x00007ffff6ce0c95 in abort () from /lib64/libc.so.6
    #2  0x000000000116a0ee in node::Abort () at ../../src/node_errors.cc:254
    #3  0x000000000116af3e in node::OnFatalError (location=0x3673e18 "v8::HandleScope::CreateHandle()", message=0x3673de8 "Cannot create a handle without a HandleScope") at ../../src/node_errors.cc:441
    #4  0x00000000013e6751 in v8::Utils::ReportApiFailure (location=location@entry=0x3673e18 "v8::HandleScope::CreateHandle()", message=message@entry=0x3673de8 "Cannot create a handle without a HandleScope")
        at ../../deps/v8/src/api/api.cc:279
    #5  0x0000000001683f91 in v8::Utils::ApiCheck (message=0x3673de8 "Cannot create a handle without a HandleScope", location=0x3673e18 "v8::HandleScope::CreateHandle()", condition=<optimized out>)
        at ../../deps/v8/src/api/api.h:144
    #6  v8::internal::HandleScope::Extend (isolate=isolate@entry=0x6079390) at ../../deps/v8/src/handles/handles.cc:93
    #7  0x00000000013c8028 in v8::internal::HandleScope::CreateHandle (value=58450354347249, isolate=0x6079390) at ../../deps/v8/src/handles/handles-inl.h:167
    #8  v8::internal::HandleScope::GetHandle (isolate=isolate@entry=0x6079390, value=58450354347249) at ../../deps/v8/src/handles/handles-inl.h:185
    #9  0x00000000016ac423 in v8::internal::HandleBase::HandleBase (isolate=0x6079390, object=<optimized out>, this=<optimized out>) at ../../deps/v8/src/handles/handles-inl.h:20
    #10 v8::internal::Handle<v8::internal::SeqOneByteString>::Handle (isolate=0x6079390, object=..., this=<optimized out>) at ../../deps/v8/src/handles/handles-inl.h:52
    #11 v8::internal::handle<v8::internal::SeqOneByteString> (isolate=0x6079390, object=...) at ../../deps/v8/src/handles/handles-inl.h:64
    #12 v8::internal::FactoryBase<v8::internal::Factory>::NewRawOneByteString (this=this@entry=0x6079390, length=35, allocation=allocation@entry=v8::internal::AllocationType::kYoung)
        at ../../deps/v8/src/heap/factory-base.cc:545
    #13 0x00000000016d83be in v8::internal::Factory::NewStringFromOneByte (this=this@entry=0x6079390, string=..., allocation=allocation@entry=v8::internal::AllocationType::kYoung)
        at /usr/include/c++/8/ext/new_allocator.h:86
    #14 0x00000000013fdc75 in v8::(anonymous namespace)::NewString (string=..., type=v8::NewStringType::kNormal, factory=0x6079390) at ../../deps/v8/src/api/api.cc:6371
    #15 v8::String::NewFromOneByte (isolate=0x6079390, data=0x35f4380 "Canceled because of SSL destruction", type=v8::NewStringType::kNormal, length=<optimized out>) at ../../deps/v8/src/api/api.cc:6429
    #16 0x000000000102c2ba in node::OneByteString (isolate=0x6079390, data=0x35f4380 "Canceled because of SSL destruction", length=-1) at ../../src/util-inl.h:187
    #17 0x0000000001100dc0 in node::StreamReq::Done (this=0x62d3330, status=-125, error_str=0x35f4380 "Canceled because of SSL destruction") at ../../src/stream_base-inl.h:284
    #18 0x0000000001382318 in node::crypto::TLSWrap::InvokeQueued (this=0x62d4af0, status=-125, error_str=0x35f4380 "Canceled because of SSL destruction") at ../../src/crypto/crypto_tls.cc:379
    #19 0x000000000138719c in node::crypto::TLSWrap::Destroy (this=0x62d4af0) at ../../src/crypto/crypto_tls.cc:1243
    #20 0x0000000001381fec in node::crypto::TLSWrap::~TLSWrap (this=0x62d4af0, __in_chrg=<optimized out>) at ../../src/crypto/crypto_tls.cc:353
    #21 0x00000000013820fa in node::crypto::TLSWrap::~TLSWrap (this=0x62d4af0, __in_chrg=<optimized out>) at ../../src/crypto/crypto_tls.cc:354
    #22 0x00000000010c1cf4 in node::BaseObject::DeleteMe (data=0x62d4af0) at ../../src/env.cc:1685
    #23 0x00000000010b1655 in node::Environment::RunCleanup (this=0x60f6c50) at ../../src/env.cc:701
    #24 0x000000000102a4fd in node::FreeEnvironment (env=0x60f6c50) at ../../src/api/environment.cc:371
    #25 0x000000000102727e in node::FunctionDeleter<node::Environment, &node::FreeEnvironment>::operator() (this=0x7fffffffde50, pointer=0x60f6c50) at ../../src/util.h:636
    #26 0x0000000001026d31 in std::unique_ptr<node::Environment, node::FunctionDeleter<node::Environment, &node::FreeEnvironment> >::~unique_ptr (this=0x7fffffffde50, __in_chrg=<optimized out>)
        at /usr/include/c++/8/bits/unique_ptr.h:277
    #27 0x00000000011d5f5f in node::NodeMainInstance::Run (this=0x7fffffffdef0, env_info=0x6003060 <node::env_info>) at ../../src/node_main_instance.cc:135
    #28 0x00000000011118f6 in node::Start (argc=2, argv=0x7fffffffe168) at ../../src/node.cc:1083
    #29 0x00000000029c59cd in main (argc=2, argv=0x7fffffffe168) at ../../src/node_main.cc:127
    
  4. niyan-ly commented on May 18, 2021

    @niyan-ly
    Author

    Will this issue affect other unref APIs?
    And are there any workarounds? Currently, it seems like waiting a few milliseconds(like 40) is one way. But code like this is kind of confusing.

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

    confirmed-bugIssues and PRs for confirmed bugs.tlsIssues and PRs related to the tls subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions