From d35398875d03d17bab31ec2e59c0a71fc500bebf Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Thu, 21 May 2026 10:48:46 -0500 Subject: [PATCH] fix(PingConexion): reduce TCP connection timeout to 2 seconds and add error message on failure --- rest/controllers/servidor_controller.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/rest/controllers/servidor_controller.go b/rest/controllers/servidor_controller.go index 3e55cd9..551419f 100755 --- a/rest/controllers/servidor_controller.go +++ b/rest/controllers/servidor_controller.go @@ -252,7 +252,7 @@ func PingConexion(c *fiber.Ctx) error { // Intentar conexión TCP addr := fmt.Sprintf("%s:%s", conexion.Servidor.IpServidor, conexion.Puerto) - conn, err := net.DialTimeout("tcp", addr, 5*time.Second) + conn, err := net.DialTimeout("tcp", addr, 2*time.Second) if err == nil { conn.Close() exitoso = true @@ -269,11 +269,17 @@ func PingConexion(c *fiber.Ctx) error { } } + errorMsg := "" + if !exitoso { + errorMsg = fmt.Sprintf("No se pudo conectar a %s:%s", conexion.Servidor.IpServidor, conexion.Puerto) + } + return c.JSON(fiber.Map{ "exitoso": exitoso, "tiempo": tiempoMs, "host": conexion.Servidor.IpServidor, "puerto": conexion.Puerto, "tipo": conexion.TipoDb.Nombre, + "error": errorMsg, }) }