Repository navigation
fix(relay): stop the relay reopening a broker after quit #19963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nwparker
wants to merge
9
commits into
nwparker/relay-unreadable-session-taxonomy
Choose a base branch
from
nwparker/relay-lifecycle-fences
base: nwparker/relay-unreadable-session-taxonomy
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
eca1bb4
refactor(relay): extract the revoke-outbox flush into its own module
nwparker ac81bcd
fix(relay): make the quit fence hard, and route quit to the terminal …
nwparker 3ec7b8a
fix(relay): drain the revoke outbox on one broker, not one open per item
nwparker 0ba31b2
fix(relay): stop a mid-read profile switch reporting as a sign-out
nwparker 67d950c
test(relay): pin RelayControlClient teardown before, and twice after,…
nwparker 9dd6f92
docs(relay): cross-reference the terminal stop() and the re-armable f…
nwparker a63e57a
test(relay): ratchet which teardown each lifecycle event calls
nwparker c0907f7
docs(relay): address the teardown ratchet's docstring to whoever it g…
nwparker 77d8b28
fix(relay): make the quit teardown terminal on the committed handler,…
nwparker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
src/main/runtime/relay/relay-lifecycle-auth-context-identity-race.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import { describe, expect, it, vi } from 'vitest' | ||
| import { RELAY_HOST_CLOSE_REASON } from '../../../shared/relay-host-close-reason' | ||
|
|
||
| // Same taxonomy question 8972d744 answered for the session file, asked of the | ||
| // other null exit: readRelayAuthContext re-reads the profile after the refresh, | ||
| // and a profile switch landing in that window is not a sign-out. | ||
| const fakes = vi.hoisted(() => ({ | ||
| ensureActiveOrcaProfile: vi.fn(), | ||
| readFreshOrcaCloudSession: vi.fn() | ||
| })) | ||
|
|
||
| vi.mock('../../orca-profiles/profile-index-store', () => ({ | ||
| ensureActiveOrcaProfile: fakes.ensureActiveOrcaProfile | ||
| })) | ||
| vi.mock('../../orca-profiles/profile-cloud-session-refresh', () => ({ | ||
| readFreshOrcaCloudSession: fakes.readFreshOrcaCloudSession | ||
| })) | ||
|
|
||
| import { readRelayAuthContext } from './relay-auth-context' | ||
| import { RelayAuthCoordinator } from './relay-auth-coordinator' | ||
|
|
||
| const authConfig = {} as never | ||
|
|
||
| function profile(id: string, cloud: object | null) { | ||
| return { profile: { id, ...(cloud ? { cloud } : {}) } } | ||
| } | ||
|
|
||
| const signedIn = { userId: 'u1', cloudProfileId: 'cp1', activeOrgId: 'org-1' } | ||
|
|
||
| function foundSession() { | ||
| return { | ||
| status: 'found', | ||
| session: { accessToken: 'access-1', capabilities: { flags: { 'relay.use': true } } } | ||
| } | ||
| } | ||
|
|
||
| describe('readRelayAuthContext profile-switch race', () => { | ||
| it('refuses to call a mid-read profile switch a sign-out', async () => { | ||
| // ensureActiveOrcaProfile is called twice — once before the refresh and once | ||
| // after, because refresh and org selection can rewrite cloud linkage. A | ||
| // switch between them means "re-read", not "the cloud session is gone". | ||
| fakes.ensureActiveOrcaProfile | ||
| .mockReturnValueOnce(profile('profile-1', signedIn)) | ||
| .mockReturnValueOnce(profile('profile-2', signedIn)) | ||
| fakes.readFreshOrcaCloudSession.mockResolvedValue(foundSession()) | ||
|
|
||
| await expect(readRelayAuthContext(authConfig, '/tmp/x')).rejects.toThrow( | ||
| 'orca_profile_switched_during_read' | ||
| ) | ||
| }) | ||
|
|
||
| it('classifies the switch as auth_unavailable, never signed_out', async () => { | ||
| fakes.ensureActiveOrcaProfile | ||
| .mockReturnValueOnce(profile('profile-1', signedIn)) | ||
| .mockReturnValueOnce(profile('profile-2', signedIn)) | ||
| fakes.readFreshOrcaCloudSession.mockResolvedValue(foundSession()) | ||
| const broker = { closeNow: vi.fn() } | ||
| const coordinator = new RelayAuthCoordinator({ | ||
| readContext: () => readRelayAuthContext(authConfig, '/tmp/x'), | ||
| openBroker: async () => broker, | ||
| onStatus: vi.fn() | ||
| }) | ||
| coordinator.reconcile() | ||
|
|
||
| const result = await coordinator.waitForLiveBrokerResult(0) | ||
| expect(result).toEqual({ broker: null, offlineReason: 'auth_unavailable' }) | ||
| // SIGNED_OUT is terminal on the wire — the phone latches it and arms no retry. | ||
| expect(broker.closeNow).not.toHaveBeenCalledWith(RELAY_HOST_CLOSE_REASON.SIGNED_OUT) | ||
| }) | ||
|
|
||
| it('still reports a profile that genuinely has no cloud linkage as gone', async () => { | ||
| fakes.ensureActiveOrcaProfile | ||
| .mockReturnValueOnce(profile('profile-1', signedIn)) | ||
| .mockReturnValueOnce(profile('profile-1', null)) | ||
| fakes.readFreshOrcaCloudSession.mockResolvedValue(foundSession()) | ||
|
|
||
| await expect(readRelayAuthContext(authConfig, '/tmp/x')).resolves.toBeNull() | ||
| }) | ||
|
|
||
| it('returns the post-refresh identity when the profile held still', async () => { | ||
| fakes.ensureActiveOrcaProfile | ||
| .mockReturnValueOnce(profile('profile-1', signedIn)) | ||
| .mockReturnValueOnce(profile('profile-1', { ...signedIn, activeOrgId: 'org-2' })) | ||
| fakes.readFreshOrcaCloudSession.mockResolvedValue(foundSession()) | ||
|
|
||
| await expect(readRelayAuthContext(authConfig, '/tmp/x')).resolves.toEqual({ | ||
| identity: { userId: 'u1', profileId: 'cp1', organizationId: 'org-2' }, | ||
| accessToken: 'access-1', | ||
| relayEntitled: true | ||
| }) | ||
| }) | ||
| }) |
Oops, something went wrong.
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.
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.
The quit call-site cross-references are now stale. This comment says quit calls
stop()frombefore-quit, and the sibling comment onfenceAndCloseNow(desktop-relay-service.ts:120) still says quit deliberately does not use the fence.77d8b28aa2did the opposite of both:before-quitis back on the fence and the terminalstop()moved towill-quit. These are the comments the PR leans on to keep the split legible, so they should describe the new arrangement.