fix(PingConexion): reduce TCP connection timeout to 2 seconds and add error message on failure

This commit is contained in:
Lizandro Guarnizo
2026-05-21 10:48:46 -05:00
parent 194db3e9ed
commit d35398875d
+7 -1
View File
@@ -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,
})
}