From ee5917adc619af4657383b43dfc7e6ab971896e1 Mon Sep 17 00:00:00 2001 From: tinkle-community Date: Sun, 5 Jul 2026 23:42:35 +0900 Subject: [PATCH] fix: raise timeout for trader lifecycle calls to survive slow stop/restart MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Live click-through showed PUT /traders/:id taking 33.8s (stopping the running instance waits for its in-flight cycle and monitor goroutines) while the axios default timeout is 30s — the frontend aborted a request that succeeded server-side and reported a false launch failure. Create/update/start now use a 120s ceiling. --- web/src/lib/api/traders.ts | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/web/src/lib/api/traders.ts b/web/src/lib/api/traders.ts index 978b108a..b064319f 100644 --- a/web/src/lib/api/traders.ts +++ b/web/src/lib/api/traders.ts @@ -6,6 +6,12 @@ import type { import { API_BASE, httpClient } from './helpers' import { ApiError } from '../httpClient' +// Create/update/start legitimately run long: stopping a live trader waits for +// its in-flight cycle and monitors, and creation probes the exchange (~35s +// worst case observed). The default 30s axios timeout aborts mid-operation and +// reports a false failure, so these calls get their own generous ceiling. +const TRADER_LIFECYCLE_TIMEOUT_MS = 120_000 + function throwApiError( message: string, errorKey?: string, @@ -33,10 +39,11 @@ export const traderApi = { }, async createTrader(request: CreateTraderRequest): Promise { - const result = await httpClient.post( - `${API_BASE}/traders`, - request - ) + const result = await httpClient.request(`${API_BASE}/traders`, { + method: 'POST', + data: request, + timeout: TRADER_LIFECYCLE_TIMEOUT_MS, + }) if (!result.success) { throwApiError( result.message || 'Failed to create trader', @@ -54,8 +61,9 @@ export const traderApi = { }, async startTrader(traderId: string): Promise { - const result = await httpClient.post( - `${API_BASE}/traders/${traderId}/start` + const result = await httpClient.request( + `${API_BASE}/traders/${traderId}/start`, + { method: 'POST', timeout: TRADER_LIFECYCLE_TIMEOUT_MS } ) if (!result.success) { throwApiError( @@ -117,9 +125,9 @@ export const traderApi = { traderId: string, request: CreateTraderRequest ): Promise { - const result = await httpClient.put( + const result = await httpClient.request( `${API_BASE}/traders/${traderId}`, - request + { method: 'PUT', data: request, timeout: TRADER_LIFECYCLE_TIMEOUT_MS } ) if (!result.success) { throwApiError(