From 49bdef68c7ff3b56ba6463d9ec066aa2d8c1ad15 Mon Sep 17 00:00:00 2001 From: jim800121chen Date: Mon, 9 Mar 2026 21:39:35 +0800 Subject: [PATCH] fix: increase device connect timeout from 30s to 60s KL520 USB Boot flow needs ~40s: retry connect (3x2s) + firmware load + 5s reboot wait + reconnect retry (3x3s). 30s was too tight. Co-Authored-By: Claude Opus 4.6 --- .../server/internal/api/handlers/device_handler.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/edge-ai-platform/server/internal/api/handlers/device_handler.go b/edge-ai-platform/server/internal/api/handlers/device_handler.go index 5eea516..17ccc46 100644 --- a/edge-ai-platform/server/internal/api/handlers/device_handler.go +++ b/edge-ai-platform/server/internal/api/handlers/device_handler.go @@ -71,9 +71,9 @@ func (h *DeviceHandler) GetDevice(c *gin.Context) { func (h *DeviceHandler) ConnectDevice(c *gin.Context) { id := c.Param("id") - // Run connect with a 30-second timeout to avoid blocking the HTTP - // request for over a minute when the SDK connect hangs. - ctx, cancel := context.WithTimeout(c.Request.Context(), 30*time.Second) + // KL520 USB Boot flow can take ~40s: retry connect (3x2s) + firmware + // load + 5s reboot wait + reconnect retry (3x3s). Use 60s timeout. + ctx, cancel := context.WithTimeout(c.Request.Context(), 60*time.Second) defer cancel() errCh := make(chan error, 1) @@ -94,7 +94,7 @@ func (h *DeviceHandler) ConnectDevice(c *gin.Context) { case <-ctx.Done(): c.JSON(504, gin.H{ "success": false, - "error": gin.H{"code": "CONNECT_TIMEOUT", "message": fmt.Sprintf("device connect timed out after 30s for %s", id)}, + "error": gin.H{"code": "CONNECT_TIMEOUT", "message": fmt.Sprintf("device connect timed out after 60s for %s", id)}, }) } }