Repository navigation
Description
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
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:
WillReleaseScriptContextcallsStopPolling()which joins the embed thread and drainsembed_sem_.
But if the embed thread had already posted aUvRunOncetask, that task stays in the main thread's queue.DidCreateScriptContextreuses the sameNodeBindingsfor the new page.
It sets the new environment withset_uv_env()and posts a task that will callPrepareEmbedThread()andStartPolling().- The stale
UvRunOncetask runs before that task.
Nothing stops it, because its weak pointer is still valid anduv_env()is set again.
It postsembed_sem_, although no embed thread exists yet. - 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 insideuv_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.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fields👀 Unsorted Items
Activity
kmamal commentedon Nov 25, 2026
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.