Bladeren bron

fix(fleet): stop reporting a slow install as a network failure (#1894) (#1929)

Nacho 4 weken geleden
bovenliggende
commit
fcf4b9fe28

+ 2 - 0
app/public/locales/en/translation.json

@@ -1330,6 +1330,8 @@
       "installDone": "Agent installed and reporting.",
       "installPending": "Agent installed; waiting for it to report (up to 40s).",
       "installFail": "Install failed",
+      "sshTimeout": "The server stopped waiting for the router. The command may still be running: reload in a minute and check the agent.",
+      "sshUnreachable": "The browser could not reach the server. Check the connection and try again.",
       "uninstall": "Uninstall",
       "uninstalling": "Uninstalling…",
       "uninstalled": "Uninstalled",

+ 2 - 0
app/public/locales/es/translation.json

@@ -1330,6 +1330,8 @@
       "installDone": "Agente instalado y empujando.",
       "installPending": "Agente instalado; esperando a que empuje (hasta 40 s).",
       "installFail": "Fallo al instalar",
+      "sshTimeout": "El servidor dejó de esperar al router. El comando puede seguir corriendo: recarga en un minuto y mira el agente.",
+      "sshUnreachable": "El navegador no pudo hablar con el servidor. Revisa la conexión y vuelve a intentarlo.",
       "uninstall": "Desinstalar",
       "uninstalling": "Desinstalando…",
       "uninstalled": "Desinstalado",

+ 12 - 3
app/src/components/routers/AgentsSection.tsx

@@ -153,6 +153,15 @@ function AgentRow({ agent, router, nowSec }: { agent?: AgentInfo; router: Router
           ? nowSec - up.ts < TIMELINE_FAILED_S
           : up.step !== 'queued' && nowSec - up.ts < TIMELINE_STALLED_S)
 
+  // #1894: los fallos que ocurren en el navegador llegan como código corto
+  // ('timeout', 'network'), no como mensaje del servidor. Traducirlos evita
+  // que la fila enseñe la palabra "network" en rojo y nada más.
+  const clientFailText = (code?: string) => {
+    if (code === 'timeout') return t('routers.agents.sshTimeout')
+    if (code === 'network') return t('routers.agents.sshUnreachable')
+    return code ?? ''
+  }
+
   const reinstall = async () => {
     if (reinstallState === 'busy') return
     // #483: primera instalación vs reinstalación: mismo endpoint (reinstall
@@ -175,7 +184,7 @@ function AgentRow({ agent, router, nowSec }: { agent?: AgentInfo; router: Router
       // #1894: el fallo NO se auto-oculta. Un error que desaparece a los 8 s
       // no se puede leer, copiar ni adjuntar a un reporte.
       setReinstallState('fail')
-      setReinstallMsg(res?.error ?? t(failKey))
+      setReinstallMsg(clientFailText(res?.error) || t(failKey))
     }
   }
 
@@ -195,7 +204,7 @@ function AgentRow({ agent, router, nowSec }: { agent?: AgentInfo; router: Router
       await refreshAgents()
     } else {
       setUninstallState('fail')
-      setUninstallMsg(res?.error ?? t('routers.agents.uninstallFail'))
+      setUninstallMsg(clientFailText(res?.error) || t('routers.agents.uninstallFail'))
     }
     window.setTimeout(() => setUninstallState('idle'), 8000)
   }
@@ -280,7 +289,7 @@ function AgentRow({ agent, router, nowSec }: { agent?: AgentInfo; router: Router
       await refreshAgents()
     } else {
       setRemoveState('fail')
-      setRemoveMsg(res?.error ?? t('routers.agents.removeFail'))
+      setRemoveMsg(clientFailText(res?.error) || t('routers.agents.removeFail'))
     }
     window.setTimeout(() => setRemoveState('idle'), 8000)
   }

+ 13 - 7
app/src/data/DataProvider.tsx

@@ -1276,9 +1276,12 @@ export function DataProvider({ children }: { children: React.ReactNode }) {
   const reinstallAgent = useCallback(async (slug: string): Promise<{ recovered: boolean; token?: string; output?: string; error?: string } | null> => {
     if (modeRef.current !== 'live') return null
     try {
+      // #1894: el handler espera al script (hasta 300 s) y luego al primer
+      // push del agente (40 s). Con 90 s el navegador cortaba una instalación
+      // que seguía viva y la pintaba como fallo.
       const res = await fetch(`/api/agents/${encodeURIComponent(slug)}/reinstall`, {
         method: 'POST',
-        signal: AbortSignal.timeout(90_000),
+        signal: AbortSignal.timeout(360_000),
       })
       if (res.status === 401) redirectLogin()
       if (!res.ok) {
@@ -1287,8 +1290,11 @@ export function DataProvider({ children }: { children: React.ReactNode }) {
       }
       const json = (await res.json()) as { recovered: boolean; token?: string; output?: string }
       return { recovered: json.recovered, token: json.token, output: json.output }
-    } catch {
-      return { recovered: false, error: 'network' }
+    } catch (e) {
+      // #1894: dos fallos distintos que antes eran el mismo 'network': el
+      // navegador se cansó de esperar (el comando puede seguir corriendo en el
+      // router) o no hay camino hasta el servidor.
+      return { recovered: false, error: e instanceof DOMException && e.name === 'TimeoutError' ? 'timeout' : 'network' }
     }
   }, [])
 
@@ -1306,8 +1312,8 @@ export function DataProvider({ children }: { children: React.ReactNode }) {
       }
       const json = (await res.json()) as { gone: boolean; token?: boolean }
       return { gone: json.gone, token: json.token }
-    } catch {
-      return { gone: false, error: 'network' }
+    } catch (e) {
+      return { gone: false, error: e instanceof DOMException && e.name === 'TimeoutError' ? 'timeout' : 'network' }
     }
   }, [])
 
@@ -1324,8 +1330,8 @@ export function DataProvider({ children }: { children: React.ReactNode }) {
         return { error: body.message ?? `HTTP ${res.status}` }
       }
       return {}
-    } catch {
-      return { error: 'network' }
+    } catch (e) {
+      return { error: e instanceof DOMException && e.name === 'TimeoutError' ? 'timeout' : 'network' }
     }
   }, [])