pingReplica pings a replica over it's internal relay address to ensure it's reachable and alive for health purposes. It will try to ping the replica twice if the first ping fails, with a short delay between attempts.
(ctx context.Context, client http.Client, replica codersdk.Replica)
| 587 | // reachable and alive for health purposes. It will try to ping the replica |
| 588 | // twice if the first ping fails, with a short delay between attempts. |
| 589 | func pingReplica(ctx context.Context, client http.Client, replica codersdk.Replica) error { |
| 590 | const attempts = 2 |
| 591 | var err error |
| 592 | for i := 0; i < attempts; i++ { |
| 593 | err = replicasync.PingPeerReplica(ctx, client, replica.RelayAddress) |
| 594 | if err == nil { |
| 595 | return nil |
| 596 | } |
| 597 | if i < attempts-1 { |
| 598 | select { |
| 599 | case <-ctx.Done(): |
| 600 | return ctx.Err() |
| 601 | case <-time.After(1 * time.Second): |
| 602 | } |
| 603 | } |
| 604 | } |
| 605 | return err |
| 606 | } |
| 607 | |
| 608 | func (s *Server) handleRegisterFailure(err error) { |
| 609 | if s.ctx.Err() != nil { |
no test coverage detected