-
Notifications
You must be signed in to change notification settings - Fork 10
feat(transport,client-core): name a wire version skew at handshake instead of timing out #529
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
Changes from all commits
94470d4
c2e430d
a867da8
2a494a4
08235ce
2e2ec5f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import { | |
| multilineTextAlignment, | ||
| textSelection, | ||
| } from '@expo/ui/swift-ui/modifiers'; | ||
| import type { WireIncompatibilityRemedy } from '@linkcode/client-core'; | ||
| import { FOOTNOTE, SECONDARY } from '@mobile/components/form/styles'; | ||
| import { useTranslations } from 'use-intl'; | ||
|
|
||
|
|
@@ -16,6 +17,8 @@ export interface HostConnectionStateProps { | |
| url: string; | ||
| /** The underlying failure, when the controller reported one. */ | ||
| failure?: string; | ||
| /** A wire skew: retrying cannot help, one side has to update. */ | ||
| wireRemedy?: WireIncompatibilityRemedy; | ||
| onRetry: () => void; | ||
| } | ||
|
|
||
|
|
@@ -24,10 +27,21 @@ export function HostConnectionState({ | |
| status, | ||
| url, | ||
| failure, | ||
| wireRemedy, | ||
| onRetry, | ||
| }: HostConnectionStateProps): React.ReactNode { | ||
| const t = useTranslations('mobile.connection'); | ||
|
|
||
| let title = t('unavailableTitle'); | ||
| let body = t('error', { url }); | ||
| if (wireRemedy === 'update-app') { | ||
| title = t('updateAppTitle'); | ||
| body = t('updateAppBody'); | ||
| } else if (wireRemedy === 'update-host') { | ||
| title = t('updateHostTitle'); | ||
| body = t('updateHostBody'); | ||
| } | ||
|
|
||
| return ( | ||
| <Host style={{ flex: 1 }} useViewportSizeMeasurement> | ||
| <VStack spacing={16}> | ||
|
|
@@ -38,20 +52,29 @@ export function HostConnectionState({ | |
| </> | ||
| ) : ( | ||
| <> | ||
| <Image systemName="wifi.exclamationmark" size={44} modifiers={[SECONDARY]} /> | ||
| <Image | ||
| systemName={wireRemedy ? 'arrow.down.circle' : 'wifi.exclamationmark'} | ||
| size={44} | ||
| modifiers={[SECONDARY]} | ||
| /> | ||
| <VStack spacing={6}> | ||
| <Text modifiers={[TITLE, CENTERED]}>{t('unavailableTitle')}</Text> | ||
| <Text modifiers={[SECONDARY, CENTERED, textSelection(true)]}> | ||
| {t('error', { url })} | ||
| </Text> | ||
| <Text modifiers={[TITLE, CENTERED]}>{title}</Text> | ||
| <Text modifiers={[SECONDARY, CENTERED, textSelection(true)]}>{body}</Text> | ||
| </VStack> | ||
| <Button | ||
| label={t('retry')} | ||
| systemImage="arrow.clockwise" | ||
| modifiers={[buttonStyle('borderedProminent')]} | ||
| onPress={onRetry} | ||
| /> | ||
| {failure ? ( | ||
| {/* An app below the host's floor has nothing to retry: redialing only flashes | ||
| "connecting" and lands back here. Updating the host is a real action, so that | ||
| skew keeps the button. */} | ||
| {wireRemedy === 'update-app' ? null : ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing the button is right for the flip-flop problem, but it leaves That's mostly fine, because the intended remedy (an App Store update) restarts the process anyway. The mismatch is the copy: Technical detailsThe three mechanisms that together close every escape: // apps/mobile/src/runtime/use-host-client.ts:55-58
const { status, error } = controller.getSnapshot();
if (status === 'ready') return;
if (error instanceof WireIncompatibleError && error.remedy === 'update-app') return;
controller.retry();// apps/mobile/src/runtime/host-connection-pool.ts:20-28 — same id, same controller
// apps/mobile/src/runtime/host-connection-pool.ts:31-37 — prune only disposes what's not in `keep`// apps/mobile/src/components/shell/host-connection-scope.tsx:16-25
const keep = new Set(
keepHostsConnected ? hosts.map((entry) => entry.id) : host ? [host.id] : [],
);
Two ways out, either is fine:
|
||
| <Button | ||
| label={t('retry')} | ||
| systemImage="arrow.clockwise" | ||
| modifiers={[buttonStyle('borderedProminent')]} | ||
| onPress={onRetry} | ||
| /> | ||
| )} | ||
| {/* The technical line distinguishes causes on an ordinary failure; under a named skew | ||
| it only repeats the copy above in triage voice. */} | ||
| {failure && wireRemedy === undefined ? ( | ||
| <Text modifiers={[FOOTNOTE, SECONDARY, CENTERED, textSelection(true)]}> | ||
| {failure} | ||
| </Text> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import type { Transport } from '@linkcode/transport'; | ||
| import { noop } from 'foxts/noop'; | ||
| import { describe, expect, it, vi } from 'vitest'; | ||
| import type { RecoverableClient } from '../connection-controller'; | ||
| import { ConnectionController } from '../connection-controller'; | ||
| import { WireIncompatibleError } from '../wire-incompatible-error'; | ||
|
|
||
| /** The controller never drives the transport itself; the client it creates does. */ | ||
| const transport: Transport = { | ||
| connect: () => Promise.resolve(), | ||
| send: noop, | ||
| onMessage: () => noop, | ||
| onClose: () => noop, | ||
| close: noop, | ||
| }; | ||
|
|
||
| class FailingClient implements RecoverableClient { | ||
| constructor(private readonly failure: Error) {} | ||
|
|
||
| connect(): Promise<void> { | ||
| return Promise.reject(this.failure); | ||
| } | ||
|
|
||
| onClose(): () => void { | ||
| return noop; | ||
| } | ||
|
|
||
| readonly dispose = noop; | ||
| } | ||
|
|
||
| const FAST_RETRY = { retries: 2, minTimeout: 1, maxTimeout: 1 }; | ||
|
|
||
| describe('ConnectionController recovery', () => { | ||
| it('stops at once when the handshake names a wire incompatibility', async () => { | ||
| const createClient = vi.fn( | ||
| () => new FailingClient(new WireIncompatibleError('update-app', 90, 85)), | ||
| ); | ||
| const controller = new ConnectionController( | ||
| { resolve: () => ({ transport }) }, | ||
| { createClient, retry: FAST_RETRY }, | ||
| ); | ||
| controller.start(); | ||
|
|
||
| await vi.waitFor(() => expect(controller.getSnapshot().status).toBe('error')); | ||
| expect(controller.getSnapshot().error).toBeInstanceOf(WireIncompatibleError); | ||
| expect(createClient).toHaveBeenCalledTimes(1); | ||
|
|
||
| // A deliberate retry (the host may have been updated) dials once more and stops again. | ||
| controller.retry(); | ||
| expect(controller.getSnapshot().status).toBe('connecting'); | ||
| await vi.waitFor(() => expect(controller.getSnapshot().status).toBe('error')); | ||
| expect(controller.getSnapshot().error).toBeInstanceOf(WireIncompatibleError); | ||
| expect(createClient).toHaveBeenCalledTimes(2); | ||
| controller.dispose(); | ||
| }); | ||
|
|
||
| it('keeps retrying an ordinary connection failure until the budget runs out', async () => { | ||
| const createClient = vi.fn(() => new FailingClient(new Error('connection refused'))); | ||
| const controller = new ConnectionController( | ||
| { resolve: () => ({ transport }) }, | ||
| { createClient, retry: FAST_RETRY }, | ||
| ); | ||
| controller.start(); | ||
|
|
||
| await vi.waitFor(() => expect(controller.getSnapshot().status).toBe('error')); | ||
| expect(controller.getSnapshot().error).toMatchObject({ message: 'connection refused' }); | ||
| expect(createClient).toHaveBeenCalledTimes(FAST_RETRY.retries + 1); | ||
| controller.dispose(); | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.