Skip to content

Commit

Permalink
fix(gui): set a reasonable timeout on the initial params fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Jan 19, 2023
1 parent b18567c commit 50fe17b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions gui/src/components/error/ParamsVersion.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Alert, AlertTitle, Typography } from '@mui/material';
import * as React from 'react';
import { PARAM_VERSION } from '../../config';

import { PARAM_VERSION } from '../../config.js';

export interface ParamsVersionErrorProps {
root: string;
Expand All @@ -10,7 +11,7 @@ export interface ParamsVersionErrorProps {
export function ParamsVersionError(props: ParamsVersionErrorProps) {
return <Alert severity='error'>
<AlertTitle>
Parameter Version Error
Parameter version error
</AlertTitle>
<Typography>
The server returned parameters that are too old for the client to load.
Expand Down
2 changes: 1 addition & 1 deletion gui/src/components/error/ServerParams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function getErrorMessage(error: unknown): string {
export function ServerParamsError(props: ServerParamsErrorProps) {
return <Alert severity='error'>
<AlertTitle>
Server Error
Error fetching server parameters
</AlertTitle>
<Typography>
Could not fetch parameters from the ONNX web API server at <code>{props.root}</code>.
Expand Down
7 changes: 4 additions & 3 deletions gui/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable no-console */
import { mustDefault, mustExist } from '@apextoaster/js-utils';
import { merge } from 'lodash';
import { mustDefault, mustExist, timeout } from '@apextoaster/js-utils';
import * as React from 'react';
import ReactDOM from 'react-dom/client';
import { QueryClient, QueryClientProvider } from 'react-query';
Expand All @@ -16,6 +15,8 @@ import { OnnxWeb } from './components/OnnxWeb.js';
import { getApiRoot, loadConfig, mergeConfig, PARAM_VERSION } from './config.js';
import { ClientContext, ConfigContext, createStateSlices, OnnxState, StateContext } from './state.js';

export const INITIAL_LOAD_TIMEOUT = 5_000;

export async function main() {
// load config from GUI server
const config = await loadConfig();
Expand All @@ -30,7 +31,7 @@ export async function main() {

try {
// load full params from the API server and merge with the initial client config
const params = await client.params();
const params = await timeout(INITIAL_LOAD_TIMEOUT, client.params());
const version = mustDefault(params.version, '0.0.0');
if (satisfies(version, PARAM_VERSION)) {
const completeConfig = mergeConfig(config, params);
Expand Down

0 comments on commit 50fe17b

Please sign in to comment.