mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 21:27:10 +00:00
make heartbeat method simple + fix import
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
import crypto from "node:crypto";
|
import crypto from "node:crypto";
|
||||||
import net from "node:net";
|
import net from "node:net";
|
||||||
|
|
||||||
import quic from "@infisical/quic";
|
import * as quic from "@infisical/quic";
|
||||||
|
|
||||||
import { BadRequestError } from "../errors";
|
import { BadRequestError } from "../errors";
|
||||||
import { logger } from "../logger";
|
import { logger } from "../logger";
|
||||||
|
|||||||
@@ -272,24 +272,20 @@ func (g *Gateway) Listen(ctx context.Context) error {
|
|||||||
|
|
||||||
func (g *Gateway) registerHeartBeat(errCh chan error, done chan bool) {
|
func (g *Gateway) registerHeartBeat(errCh chan error, done chan bool) {
|
||||||
ticker := time.NewTicker(30 * time.Minute)
|
ticker := time.NewTicker(30 * time.Minute)
|
||||||
|
defer ticker.Stop()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(10 * time.Second)
|
|
||||||
log.Info().Msg("Registering first heart beat")
|
|
||||||
err := api.CallGatewayHeartBeatV1(g.httpClient)
|
|
||||||
if err != nil {
|
|
||||||
log.Error().Msgf("Failed to register heartbeat: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
if err := api.CallGatewayHeartBeatV1(g.httpClient); err != nil {
|
||||||
|
errCh <- err
|
||||||
|
} else {
|
||||||
|
log.Info().Msg("Gateway is reachable by Infisical")
|
||||||
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-done:
|
case <-done:
|
||||||
ticker.Stop()
|
|
||||||
return
|
return
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
log.Info().Msg("Registering heart beat")
|
|
||||||
err := api.CallGatewayHeartBeatV1(g.httpClient)
|
|
||||||
errCh <- err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@@ -307,16 +303,17 @@ func (g *Gateway) registerRelayIsActive(serverAddr string, tlsConf *tls.Config,
|
|||||||
return
|
return
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
func() {
|
func() {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) // 3s handshake timeout
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
conn, err := quic.DialAddr(ctx, serverAddr, tlsConf, quicConf)
|
conn, err := quic.DialAddr(ctx, serverAddr, tlsConf, quicConf)
|
||||||
if conn != nil {
|
if conn != nil {
|
||||||
conn.CloseWithError(0, "connection closed")
|
conn.CloseWithError(0, "connection closed")
|
||||||
}
|
}
|
||||||
// this error means quic connection is alive
|
// If we get a TLS verification error, that means the QUIC connection is working
|
||||||
|
// Any other error means the connection is not working
|
||||||
if err != nil && !strings.Contains(err.Error(), "tls: failed to verify certificate") {
|
if err != nil && !strings.Contains(err.Error(), "tls: failed to verify certificate") {
|
||||||
errCh <- err
|
log.Error().Err(err).Msg("Relay connection check failed")
|
||||||
return
|
errCh <- fmt.Errorf("relay connection check failed: %w", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user