Skip to content

Commit d02553c

Browse files
committed
Enforce a timeout on interceptor isActive checks to fix Docker issue
Previously if Docker was unresponsive for some reason, this could run forever, which would completely block UI startup. Not great! This also improves the setup generally so it handles sync errors automatically, simplifying the metadata fallback case slightly.
1 parent 0e08970 commit d02553c

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

src/api-server.ts

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ const typeDefs = gql`
9696
`;
9797

9898
// Wait for a promise, falling back to defaultValue on error or timeout
99-
const withFallback = <R>(p: Promise<R>, timeoutMs: number, defaultValue: R) =>
99+
const withFallback = <R>(p: () => Promise<R>, timeoutMs: number, defaultValue: R) =>
100100
Promise.race([
101-
p.catch((error) => {
101+
p().catch((error) => {
102102
reportError(error);
103103
return defaultValue;
104104
}),
@@ -196,18 +196,17 @@ const buildResolvers = (
196196
Interceptor: {
197197
isActivable: (interceptor: Interceptor) => {
198198
return withFallback(
199-
interceptor.isActivable(),
199+
async () => interceptor.isActivable(),
200200
interceptor.activableTimeout || INTERCEPTOR_TIMEOUT,
201201
false
202202
);
203203
},
204204
isActive: async (interceptor: Interceptor, { proxyPort }: { proxyPort: number }) => {
205-
try {
206-
return await interceptor.isActive(proxyPort);
207-
} catch (e) {
208-
reportError(e);
209-
return false;
210-
}
205+
return withFallback(
206+
async () => interceptor.isActive(proxyPort),
207+
INTERCEPTOR_TIMEOUT,
208+
false
209+
);
211210
},
212211
metadata: async function (interceptor: Interceptor, { type }: { type?: 'DETAILED' | 'SUMMARY' }) {
213212
if (!interceptor.getMetadata) return undefined;
@@ -220,16 +219,11 @@ const buildResolvers = (
220219
? INTERCEPTOR_TIMEOUT
221220
: INTERCEPTOR_TIMEOUT * 10; // Longer timeout for detailed metadata
222221

223-
try {
224-
return await withFallback(
225-
interceptor.getMetadata(metadataType),
226-
timeout,
227-
undefined
228-
);
229-
} catch (e) {
230-
reportError(e);
231-
return undefined;
232-
}
222+
return withFallback(
223+
async () => interceptor.getMetadata!(metadataType), // ! because we checked this above
224+
timeout,
225+
undefined
226+
);
233227
}
234228
},
235229

0 commit comments

Comments
 (0)