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
|
||||
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,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user