Skip to content

[Bug]: Node.js timers in the renderer stop firing after a page reload #56060

Backlog

Description

@kmamal

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project adheres to.
  • I have searched the issue tracker for a bug report that matches the one I want to file, without success.

Electron Version

45.4.1

What operating system(s) are you using?

Other Linux

Operating System Version

Debian 13 (trixie), Linux 6.12.116 (X11)

What arch are you using?

x64

Last Known Working Electron version

43.4.1

Does the issue also appear in Chromium / Google Chrome?

No

Expected Behavior

After location.reload() / webContents.reload(), Node.js timers (require('timers').setInterval) in a nodeIntegration renderer should work.

Actual Behavior

On some reloads the new page's Node.js timers stop firing after a few ticks and never resume.
No error is thrown.
DOM timers keep working.

The page only needs:

require('timers').setInterval(() => {}, 0)

That alone stalls about 1 in 200 reloads.

If each callback additionally spins for 5 ms, about half of the reloads stall:

Busy work per tick 45.4.1 39.8.10
none 2 of 450 0 of 300
1 ms 22 of 100 0 of 100
5 ms 48 of 100 0 of 100

A stalled page is never followed by another stalled page, so the stall rate tops out just under 50%.

Testcase Gist URL

https://gist.github.com/kmamal/b8273844aa809aac01b9e4b01dcbcdde

Additional Information

I've traced it to #52964 (per-environment uv loops), shipped as #53042 in 42.10.0, #53041 in 43.5.0 and #53040 in 44.0.0.

I have only tested on Linux, but all of this code is in the shared node_bindings.cc, so other platforms are probably affected too.

In-depth investigation

A reload can leave a UvRunOnce task from the old page in the main thread's queue.
That task then runs for the new page, and from then on the new page's embed thread polls the uv loop while the main thread is still running it:

  1. WillReleaseScriptContext calls StopPolling() which joins the embed thread and drains embed_sem_.
    But if the embed thread had already posted a UvRunOnce task, that task stays in the main thread's queue.
  2. DidCreateScriptContext reuses the same NodeBindings for the new page.
    It sets the new environment with set_uv_env() and posts a task that will call PrepareEmbedThread() and StartPolling().
  3. The stale UvRunOnce task runs before that task.
    Nothing stops it, because its weak pointer is still valid and uv_env() is set again.
    It posts embed_sem_, although no embed thread exists yet.
  4. The new embed thread starts with one post too many in embed_sem_.
    It consumes the extra post instead of waiting for the main thread, so from then on it polls while the main thread is inside uv_run.

Before #52964 the same leftover task was harmless.
The embed thread lived as long as the process and a reload did not restart it, so it was still blocked on embed_sem_, waiting for exactly that task.

Then the timers stall because the embed thread can call uv_backend_timeout() between the interval timer firing and its callback finishing.
libuv stops a due timer before it calls the callback, and Node re-arms the interval timer only after the JS callback returns.
Inside that window the loop has no active timer, so the timeout is -1 and the embed thread calls epoll_wait with no timeout.
When Node re-arms the timer, nothing wakes the embed thread, because UvRunOnce wraps uv_run in uv_loop_interrupt_suspend().
The embed thread stays in epoll_wait, it posts no more UvRunOnce tasks, and the timer never fires.
A longer callback widens this window, which is why busy work raises the stall rate.

As a proposed fix, StopPolling() should drop the stale task by calling weak_factory_.InvalidateWeakPtrs() after uv_thread_join.

Activity

  1. added
    has-repro-gist
    on Nov 25, 2026
  2. moved this to 👀 Unsorted Items in 45-x-yon Nov 25, 2026
  3. kmamal commented on Nov 25, 2026

    @kmamal
    Author

    I have a draft PR here: #56061

    My machine can't build electron so I can't build and test from source, but I have tested by patching the binary.

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

    45-x-ybug 🪲has-repro-gistplatform/linux

    Type

    Projects

    • Status
      👀 Unsorted Items

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions