Skip to content

frame_converter.cc creates a new ObjectTemplate on every IPC call, causing V8 crash after days of runtime #52343

Closed as not planned

Description

@yungchao

frame_converter.cc creates a new ObjectTemplate on every IPC call, causing V8 crash after days of runtime

Preflight Checklist

Electron Version

40.10.2, 40.10.3

What operating system(s) are you using?

macOS

Operating System Version

macOS (Darwin 24.5.0), Mac mini (Macmini7,1)

What arch are you using?

x64

Last Known Working Electron version

No response

Expected Behavior

The application should run stably for extended periods (days/weeks) without crashing, even with frequent synchronous IPC calls (e.g., from @electron/remote).

Actual Behavior

After 4–6 days of continuous runtime, the main process crashes with EXC_BREAKPOINT (SIGTRAP) inside V8's InstantiateFunction() when processing a synchronous IPC message. The crash occurs consistently after an idle period (~45 minutes), suggesting it is triggered by V8's idle-time Major GC (Mark-Compact with compaction).

Three independent crash reports from different app versions (40.10.2 and 40.10.3) all show the same crash path.

Testcase Gist URL

No response

Additional Information

Root Cause Analysis

The crash originates in shell/common/gin_converters/frame_converter.cc, where Converter<gin_helper::AccessorValue<content::RenderFrameHost*>>::ToV8() creates a new v8::ObjectTemplate on every call:

v8::Local<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate);
templ->SetInternalFieldCount(2);
v8::Local<v8::Object> rfh_obj =
    templ->NewInstance(isolate->GetCurrentContext()).ToLocalChecked();

This code runs on every synchronous IPC call via the following path:

ipcRenderer.sendSync()
  → ElectronApiIPCHandlerImpl::MessageSync()        // electron_api_ipc_handler_impl.cc:103
    → MakeIPCEvent()                                 // electron_api_ipc_handler_impl.cc:179
      → dict.SetGetter("senderFrame", frame)
        → Converter<AccessorValue<RFH*>>::ToV8()     // frame_converter.cc:49
          → ObjectTemplate::New(isolate)              // NEW template every time
          → templ->NewInstance(context)
            → V8 InstantiateFunction()               // CRASH here

v8::ObjectTemplate and its implicit FunctionTemplateInfo constructor are designed to be created once and reused. Creating and discarding them on every IPC call is an unusual pattern that stresses a rarely-tested V8 code path. Over millions of IPC calls (especially from @electron/remote which uses sendSync extensively), this accumulates a large number of short-lived template objects in V8's old generation heap.

When the app goes idle, V8's idle-time GC performs a Major GC (Mark-Compact with compaction), and during this process, a FunctionTemplateInfo object's bit fields become corrupted. The next IPC call after the idle period then crashes when InstantiateFunction() reads the invalid bit field.

Fully Symbolicated Crash Stack (from Breakpad minidump + symbols)

Frame 0:  InstantiateFunction(Isolate*, NativeContext, FunctionTemplateInfo, Name)  [bit-field.h:80]
Frame 1:  InstantiateObject(Isolate*, ObjectTemplateInfo, JSReceiver, bool)         [api-natives.cc:54]
Frame 2:  ApiNatives::InstantiateObject(...)                                         [api-natives.cc:514]
Frame 3:  v8::ObjectTemplate::NewInstance(context)                                   [api.cc:7227]
Frame 4:  gin::Converter<AccessorValue<RenderFrameHost*>>::ToV8()                    [frame_converter.cc:60]
Frame 5:  Dictionary::SetGetter<"senderFrame", RenderFrameHost*>()                   [converter.h:327]
Frame 6:  ElectronApiIPCHandlerImpl::MakeIPCEvent()                      [electron_api_ipc_handler_impl.cc:179]
Frame 7:  ElectronApiIPCHandlerImpl::MessageSync()                       [electron_api_ipc_handler_impl.cc:103]
Frame 8:  ElectronApiIPCStubDispatch::AcceptWithResponder()                          [api.mojom.cc:2362]
...
Frame 17: ThreadControllerWithMessagePumpImpl::DoWork()                              [task_annotator.h:113]
→ CoreFoundation CFRunLoop → AppKit → ElectronMain

Proposed Fix

Cache the ObjectTemplate using v8::Eternal so it is created only once per isolate:

static v8::Eternal<v8::ObjectTemplate> cached_templ;
if (cached_templ.IsEmpty()) {
  v8::Local<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate);
  templ->SetInternalFieldCount(2);
  cached_templ.Set(isolate, templ);
}
v8::Local<v8::ObjectTemplate> templ = cached_templ.Get(isolate);
v8::Local<v8::Object> rfh_obj =
    templ->NewInstance(isolate->GetCurrentContext()).ToLocalChecked();

This is consistent with how other parts of Electron handle ObjectTemplate creation (e.g., via gin::ObjectTemplateBuilder which caches templates).

Observations from crash reports

Report Electron Uptime before crash Idle before crash
1 (2026-07-06) 40.10.2 ~4 days unknown
2 (2026-07-12) 40.10.3 ~6 days ~45 min
3 (2026-07-13) 40.10.3 ~5.5 days ~45 min
  • All crashes on same hardware (Macmini7,1, x64, 16GB RAM)
  • All show identical crash signature: EXC_BREAKPOINT in InstantiateFunction via frame_converter.cc
  • The code in main, 41-x-y, 42-x-y, and 43-x-y branches is identical — this issue affects all current Electron versions

Activity

  1. nikwen commented on Jul 14, 2026

    @nikwen
    Member

    Thanks for reporting!

    1. Could you please install the latest Electron 43 version and test if it crashes for you, too? Electron 40 is no longer supported.
    2. Could you please test if you see the same crash on Electron 43 without the @electron/remote module? I'd like to isolate if this issue is a result of a bug in that module or in Electron itself. It's not recommended to use @electron/remote.
    3. If it reproduces on Electron 43 without the @electron/remote module, could you please download Electron Fiddle, use it to create a small sample app that allows maintainers to reproduce this issue, and upload it as a GitHub gist from Fiddle? Also, please share an updated stacktrace in that case.
  2. added theissue type on Jul 14, 2026
  3. electron-issue-triage commented on Jul 14, 2026

    @electron-issue-triage

    Hello @yungchao. Thanks for reporting this and helping to make Electron better!

    Would it be possible for you to make a standalone testcase with only the code necessary to reproduce the issue? For example, Electron Fiddle is a great tool for making small test cases and makes it easy to publish your test case to a gist that Electron maintainers can use.

    Stand-alone test cases make fixing issues go more smoothly: it ensure everyone's looking at the same issue, it removes all unnecessary variables from the equation, and it can also provide the basis for automated regression tests.

    Now adding the blocked/need-repro Needs a test case to reproduce the bug label for this reason. After you make a test case, please link to it in a followup comment. This issue will be closed in 10 days if the above is not addressed.

  4. added 2 commits that reference this issue on Jul 15, 2026
    31e64ab
    04efd16
  5. yungchao commented on Jul 15, 2026

    @yungchao
    Author

    Atttach crash report on mac computers.

    Archive.zip

  6. removed
    blocked/need-repro
    on Jul 15, 2026
  7. yungchao commented on Jul 16, 2026

    @yungchao
    Author

    Attach minidump .dmp files

    minidump.zip

  8. yungchao commented on Jul 16, 2026

    @yungchao
    Author

    Seems not only sendSync, but all IPC calls from renderer to main will encounter the same issue:

    1. Every renderer→main IPC message (Message, Invoke, ReceivePostMessage,
      MessageSync) calls MakeIPCEvent, which does
      dict.SetGetter("senderFrame", frame)
      (shell/browser/electron_api_ipc_handler_impl.cc).
    2. The converter creates a fresh v8::ObjectTemplate on every call —
      there is no caching (shell/common/gin_converters/frame_converter.cc:~60):
      v8::Local<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate);
      templ->SetInternalFieldCount(2);
      v8::Local<v8::Object> rfh_obj = templ->NewInstance(...).ToLocalChecked();
      SetGetter additionally creates a getter FunctionTemplate. Net cost:
      ~2–3 V8 template serial numbers per IPC message, allocated from a
      monotonically increasing, never-recycled per-isolate counter
      (Heap::GetNextTemplateSerialNumber).
    3. V8 stores the serial number in a 29-bit bit-field
      (TemplateInfo::SerialNumberBits) whose encode() is guarded by a
      release-mode CHECK. V8's own overflow guard wraps at Smi::kMaxValue
      (2^31), which is unreachable — the CHECK fires first at 2^29.

    My previous statement about GC might be wrong, serial number overflow looks more like the root cause.

  9. nikwen commented on Jul 16, 2026

    @nikwen
    Member

    Could you please reply to the questions from my previous message?

  10. added
    blocked/need-repro
    on Jul 16, 2026
  11. yungchao commented on Jul 18, 2026

    @yungchao
    Author

    Hi Nikwen,

    I've attached an electron_ipc_crash poc project which use electron v43.1.1 to reproduce this issue, also includes a Mac crash report:

    • project: electron-ipc-crash-poc, get data via IPC (with @electron/remote and sendSync 2-method options)
    • ips file: Electron-2026-07-18-110109.ips, crashed at v8::ObjectTemplate::NewInstance(v8::Localv8::Context)

    The crash is reproduced by @electron/remote IPC method because it can create lots more IPC stress, it took ~13 hours to reproduce, if choose sendSync IPC mothod it should take much longer time. And the reason I choosed to a poc project instead of using Fiddle is because which can simuate the reported real case.

    pocproject_and_crashreport.zip

  12. removed
    blocked/need-repro
    on Jul 18, 2026
  13. yungchao commented on Jul 26, 2026

    @yungchao
    Author

    Hi Nikwen,

    A similar issue found on Windows Server 2022, you may refer to the zipped the minidump file.

    cc1c850c-d20f-4986-8237-05340d737196.dmp.zip

  14. added
    blocked/need-repro
    on Aug 17, 2026
  15. electron-issue-triage commented on Aug 28, 2026

    @electron-issue-triage

    Unfortunately, without a way to reproduce this issue, we're unable to continue investigation. This issue has been closed and will not be monitored further. If you're able to provide a minimal test case that reproduces this issue on a supported version of Electron please open a new issue and include instructions for reproducing the issue.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions