Closed
Description
The constructor of node::IsolateData
allocates strings in V8 heap before registering itself with the platform. This is not safe because an allocation can trigger GC, which relies on the platform to post tasks.
The problem reproduces with --stress-incremental-marking
flag.
> out/Release/node --stress-incremental-marking
out/Release/node[168537]: ../src/node_platform.cc:248:std::shared_ptr<node::PerIsolatePlatformData> node::NodePlatform::ForIsolate(v8::Isolate*): Assertion `data' failed.
1: node::Abort() [out/Release/node]
2: 0x5645d4c25a8d [out/Release/node]
3: node::NodePlatform::ForIsolate(v8::Isolate*) [out/Release/node]
4: node::NodePlatform::CallOnForegroundThread(v8::Isolate*, v8::Task*) [out/Release/node]
5: v8::internal::IncrementalMarking::Start(v8::internal::GarbageCollectionReason) [out/Release/node]
6: v8::internal::PagedSpace::RefillLinearAllocationAreaFromFreeList(unsigned long) [out/Release/node]
7: v8::internal::PagedSpace::RawSlowRefillLinearAllocationArea(int) [out/Release/node]
8: v8::internal::PagedSpace::SlowRefillLinearAllocationArea(int) [out/Release/node]
9: v8::internal::Heap::AllocateOneByteInternalizedString(v8::internal::Vector<unsigned char const>, unsigned int) [out/Release/node]
10: v8::internal::Factory::NewOneByteInternalizedString(v8::internal::Vector<unsigned char const>, unsigned int) [out/Release/node]
11: v8::internal::StringTable::LookupKey(v8::internal::Isolate*, v8::internal::StringTableKey*) [out/Release/node]
12: v8::internal::Factory::InternalizeOneByteString(v8::internal::Vector<unsigned char const>) [out/Release/node]
13: v8::String::NewFromOneByte(v8::Isolate*, unsigned char const*, v8::NewStringType, int) [out/Release/node]
14: node::IsolateData::IsolateData(v8::Isolate*, uv_loop_s*, node::MultiIsolatePlatform*, unsigned int*) [out/Release/node]
15: node::Start(uv_loop_s*, int, char const* const*, int, char const* const*) [out/Release/node]
16: node::Start(int, char**) [out/Release/node]
17: __libc_start_main [/lib/x86_64-linux-gnu/libc.so.6]
18: _start [out/Release/node]
A fix would be to move the allocating code after platform_->RegisterIsolate(this, event_loop);
If that sounds good, I will create a PR.