Repository navigation
perf(polling): remove idle polling from live sessions - #2919
Conversation
1374cc2 to
f5c3f6d
Compare
|
Thank you for removing the idle polling and adding tests. I am keeping this open for the reused-page event bridge at f5c3f6d. wireConnectionEvents swallows the duplicate exposeFunction error, leaving the previous client's onConnectionChange callback installed. The existing callback also carries __wppWired, so the second client does not replace the listeners. Running the actual method for two successive clients on one page and emitting conn.logout updates the first client to disconnected, leaves the second client connected, and reports disconnectedMobile for the first session only. Please replace or redirect the existing binding to the current client and add a two-client reused-page regression. The five Host callbacks covered by #2924 do not include this newly introduced callback. |
75fff42 to
a42441d
Compare
|
Thanks @joaosouz4dev — fixed at a42441d. The binding is now replaced, not swallowed. Two-client reused-page regression added. Runs Also noted on #2924 — the callback is now in the Host-callback set, so it's covered alongside the other five. Checks are green on a42441d. |
|
Thank you, @Omix01, for the per-page dispatcher and reused-page regression. At a42441d the previous-client callback concern is resolved. Before merging the event-based watcher, please preserve the real-unpair guard from #2931 in the new onConnectionChange method. It currently assigns connected=false and emits disconnectedMobile whenever isRegistered is false, including an initial null-to-false transition. Replacing the interval with this method would discard that fix. Please cover never-paired false, true-to-false, and the current-client reused-page dispatch together. |
Replace the permanent 1s WPP.conn.isRegistered() poll with wa-js connection events forwarded through an exposed onConnectionChange. Keep the real-unpair guard: only a registered -> unregistered transition emits disconnectedMobile, so a never-paired page that starts at false does not report a disconnect. A reused page redirects its existing binding to the newest client. Drop the dead 5s checkStart interval and its unused method/field. Assign the in-page error handlers once per document instead of on a 500ms interval.
a42441d to
faab352
Compare
|
Thanks @joaosouz4dev — fixed at I rebased onto Coverage now includes all three cases:
I also updated the #2931 watcher tests in |
|
Merged at de07dab. Thank you, @Omix01, for addressing the review and adding the regression coverage. The event watcher now preserves the true-to-false unpair guard and does not emit a disconnect for a never-paired false state. Reused-page events are routed to the current client, and a stale initial read cannot overwrite a newer event. I withdrew the previous blocker. The combined changes passed 90 lifecycle/regression tests, types, lint and build; six independent bridge checks exercised the actual injected event registration and dispatch logic. |
Three permanent background timers ran for the whole lifetime of every session and every renderer:
WhatsapppolledWPP.conn.isRegistered()once per second viapage.evaluate, forever.HostLayer.start()scheduled a 5scheckStart()interval that calledneedsToScan()and discarded the result (dead code).unregisterServiceWorkerinjected a 500mssetIntervalthat only reassignedwindow.onerror/window.onunhandledrejection.Replace the 1s poll with wa-js connection events (
conn.authenticated,conn.main_ready,conn.logout,conn.require_auth) forwarded through an exposed function;disconnectedMobileis still emitted on the unpaired transition. Drop the dead 5s interval and assign the error handlers once per document. For N sessions this removes Npage.evaluatecalls per second plus two always-on timers per session/renderer.Refs #2831 — long-running sessions grow memory/CPU over hours; this removes the always-on timers that keep a session busy while idle.
Changes proposed in this pull request
src/api/whatsapp.ts: replace the forever 1sWPP.conn.isRegistered()poll with wa-js connection events forwarded to Node through an exposedonConnectionChange;disconnectedMobileis still emitted (deduped) on the unpaired transition and the initial state is seeded once inafterPageScriptInjected.src/api/layers/host.layer.ts: remove the dead 5scheckStartinterval (result was discarded) and its unused method/field; QR detection is unchanged and still driven on demand byWPP.on('conn.auth_code_change')→checkQrCode.src/controllers/browser.ts: assignwindow.onerror/window.onunhandledrejectiononce per document instead of on a 500ms interval.src/tests/07.idle-polling.test.ts: add 4 regression tests — no periodicevaluate;disconnectedMobileemitted once;start()schedules no 5s poll; injected document script contains nosetInterval..github/workflows/build.yml: run the new spec in CI.To test (it takes a while):
npm install github:Omix01/wppconnect#perf/idle-polling