GeezerVison is showing github.com — fix(browser): copy sign-ins to a remote server's pages without stalling the app by Hona · Pull Request #65339 · anomalyco/opencode
Conversation
What a person saw
- With Share sign-ins with remote servers on, opening a session on a remote server froze the whole app for seconds to minutes.
- The remote browser pane attached late or attached again and again, and each new attempt made the freeze longer.
- Quitting waited until every copy finished.
Cause
- One read fetched the whole store.
link.ts:19-24 read a single cookie with cookies.get({ domain, path, name }). Electron answers a get that has no url by fetching every cookie the store holds and filtering in the main process (Cookies::Get → GetAllCookies in electron_api_cookies.cc, Electron 44.9.1).
- The first copy made that read 4 times per cookie.
link.ts:84-94 reconciled each cookie by itself: 2 reads per cookie, then 2 more for the echo of each write. That is 4N reads of N cookies. At N = 3,000: 12,000 reads, 36 million cookie objects built in the main process.
- The attachment waited for the copy, and nothing could stop it.
pane.ts:310 awaited profile.link (profile/index.ts:673) inside an uninterruptible acquireRelease. The 15 s registration timer (pane-machine.ts:8) fired, the window registered again, and a second partition started a second copy beside the first. runtime.dispose() waited for all of them at quit.
| One read of the profile's store (Electron 44.9.1, Windows) |
500 cookies |
3,000 cookies |
get({ domain, path, name }) (dev) |
4.1 ms |
30.5 ms |
get({ url, name }) (this PR) |
0.13 ms |
0.21 ms |
get({}) (whole list) |
5 ms |
42.8 ms |
Fix
- First copy, O(N): each store's list is read once, the two are compared in memory through the same
reconcileCookie rule (planCopy), and only the differences are written, 16 at a time with a turn of the event loop between batches.
- A change, O(1): a change that reports what both stores already agreed on (the echo of the mirror's own write) costs no read. Any other change asks each store for one site's cookies,
get({ url: "https://host/path", name }), then matches domain and path exactly as before. The whole-store read remains only for a path that no address can name (a space, ?, #).
- Cancellable: unlink, dispose and quit stop the copy at its next batch and drop the reconciles that wait.
- Attach no longer waits:
profile.link returns at once. Only a page that is about to load waits for the copy (signedIn), through the hook that already holds a load for content filters. No timer is involved, and a registration that ends takes its copy along.
- State: a small machine in
link-machine.ts: copying → following → stopped.
- No flag: this is a fix; the setting, the partition a remote session uses and the direction cookies flow are unchanged.
Before:
sequenceDiagram
participant W as Window
participant P as Pane (main)
participant M as Mirror
participant S as Remote server
W->>P: register
P->>M: link, awaited
Note over M: 4N whole-store reads
Note over P: 15 s timer fires
P-->>W: registration closed
W->>P: register again
P->>M: link, second copy beside the first
M-->>P: copy done
P->>S: attach
Loading
After:
sequenceDiagram
participant W as Window
participant P as Pane (main)
participant M as Mirror
participant S as Remote server
W->>P: register
P->>M: link, returns at once
P->>S: attach
S-->>P: attached
P-->>W: registered
W->>P: load restored tab
P->>M: signedIn(signal)
Note over M: 2 list reads, N writes in batches of 16
M-->>P: copy ended
Note over P: page loads signed in
Loading
Measurements
Pinned Electron 44.9.1 on Windows, through electron-run.ts, hidden windows, made-up cookies (6 per host: domain, host-only, plain-http on a path), empty remote partitions. "Stall" is the longest time the main process's event loop did not turn.
| Cookies |
Mirrors |
dev: copy finished |
dev: main CPU / stall |
PR: copy finished |
PR: main CPU / stall |
| 500 |
1 |
3,156 ms |
1,751 / 1,490 ms |
42 ms |
16 / 0 ms |
| 500 |
5 |
16,384 ms |
8,687 / 5,126 ms |
176 ms |
297 / 24 ms |
| 1,500 |
1 |
26,737 ms |
15,359 / 14,113 ms |
131 ms |
141 / 10 ms |
| 1,500 |
5 |
over 55 s |
no result |
444 ms |
484 / 50 ms |
| 3,000 |
1 |
over 55 s |
no result |
232 ms |
282 / 29 ms |
| 3,000 |
5 |
not run |
not run |
897 ms |
1,078 / 83 ms |
| 3,291 |
1 |
not run |
not run |
236 ms |
250 / 31 ms |
| 3,291 |
5 |
not run |
not run |
982 ms |
999 / 123 ms |
- "over 55 s": the harness ends a fixture at 55 s; the main process was too busy to print a result at its own 30 s cap.
- 3,291: 6,000 cookies were seeded. Chromium keeps at most about 3,300 per store, so that is the largest store there is.
|
dev |
PR |
Quit with a copy under way: runtime.dispose() |
22,872 ms (1,500 cookies) |
1 ms (3,000 cookies) |
| Stop a mirror during its copy: until both stores answer again |
14,917 ms (1,500 cookies) |
1 ms (3,000 cookies, 80 written) |
| 50 page writes of one cookie reach the partition (500 cookies, 1 mirror) |
200 ms |
36 ms |
| The same at 3,000 cookies, 5 mirrors |
not run |
48 ms |
Log
Main log; every field is a number or a string, and none names a cookie or a site.
info browser sign-in copy started { copy }
info browser sign-in copy finished { copy, profile, remote, toRemote, toProfile, refused, ms } (warn, with cause, when refused > 0)
info browser sign-in copy cancelled { copy, written, ms }
warn browser sign-in copy failed { copy, cause, ms }
warn browser sign-in change was not copied { copy, failures, cause } (1st, 10th, 100th failure)
warn browser shared sign-ins were not removed { copy, kept, cause }
Tests
profile/link.test.ts: counting stores. 3,000 cookies on both sides → 2 list reads, 0 per-cookie reads, 0 writes. 3,000 on one side → 3,000 writes, 0 per-cookie reads, echoes included. One change → 1 scoped read per store at 10 and at 3,000 cookies. Cancel, failure, and what a link waits for. The mirror cases fail on dev.
profile/electron-link.test.ts: the same counts and the copied cookies on the pinned Electron's own stores, for domain, host-only, secure, plain, path-scoped and session cookies and two cookies of one name under one host.
electron-sign-in-copy.test.ts: the real pane against a stand-in remote server with a copy held open. The attachment completes, the restored tab loads signed in after the copy, a registration that is replaced has its copy cancelled, and quit does not wait.
Limits
- One list read holds the main process about 30 ms at 3,000 cookies. Five mirrors that start together read five lists: one stall of 83 to 123 ms.
- A write a store refused is not retried by a later no-change event.
dev reread the key on every event, and for such a key would then remove the cookie from the profile.
- A page waits for the copy without a deadline. The person can stop the load; the copy ends when both list reads answer or fail.
- Partitioned cookies: the scoped read returns them as the unscoped one did (measured). Electron's
cookies.set cannot write a partition key, as before.
- Not in this PR: a partition is left behind per registration; there is one mirror per attachment, not per server; the mirror is two-way.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reviewed this but couldn't reproduce the problem or confirm the fix: the pinned Electron won't start in my sandbox (libnspr4.so is missing), so the two new Electron tests fail at launch here, as the existing Electron tests do. The fake-store tests in profile/link.test.ts and profile/link-machine.test.ts pass. tsc -b and oxlint are clean on the changed files.
The public API is unchanged. profile.link now returns { signedIn, unlink } right away instead of a promise of the unlink function, but that is internal to the browser built-in. No setting, schema, SDK or IPC shape changes.
I traced the cases that worried me most and the behaviour holds:
- A profile write or deletion that lands between the plan and its write: the stale echo is skipped, and the waiting change fixes the cookie when the copy ends.
- Stopping or unlinking a mirror while its copy runs.
- A page load cancelled while it waits for
signedIn.
The one behaviour change from dev, a refused write that isn't retried, is already in the Limits section. Nothing here blocks a merge.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|