fix(PingConexion): reduce TCP connection timeout to 2 seconds and add error message on failure
This commit is contained in:
@@ -252,7 +252,7 @@ func PingConexion(c *fiber.Ctx) error {
|
|||||||
|
|
||||||
// Intentar conexión TCP
|
// Intentar conexión TCP
|
||||||
addr := fmt.Sprintf("%s:%s", conexion.Servidor.IpServidor, conexion.Puerto)
|
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 {
|
if err == nil {
|
||||||
conn.Close()
|
conn.Close()
|
||||||
exitoso = true
|
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{
|
return c.JSON(fiber.Map{
|
||||||
"exitoso": exitoso,
|
"exitoso": exitoso,
|
||||||
"tiempo": tiempoMs,
|
"tiempo": tiempoMs,
|
||||||
"host": conexion.Servidor.IpServidor,
|
"host": conexion.Servidor.IpServidor,
|
||||||
"puerto": conexion.Puerto,
|
"puerto": conexion.Puerto,
|
||||||
"tipo": conexion.TipoDb.Nombre,
|
"tipo": conexion.TipoDb.Nombre,
|
||||||
|
"error": errorMsg,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user