| 1701 | } |
| 1702 | |
| 1703 | func (c *Controller) coordinate(client CoordinatorClient) { |
| 1704 | defer func() { |
| 1705 | cErr := client.Close() |
| 1706 | if cErr != nil { |
| 1707 | c.logger.Debug(c.ctx, "error closing Coordinate RPC", slog.Error(cErr)) |
| 1708 | } |
| 1709 | }() |
| 1710 | coordination := c.CoordCtrl.New(client) |
| 1711 | c.logger.Debug(c.ctx, "serving coordinator") |
| 1712 | select { |
| 1713 | case <-c.ctx.Done(): |
| 1714 | c.logger.Debug(c.ctx, "main context canceled; do graceful disconnect") |
| 1715 | crdErr := coordination.Close(c.gracefulCtx) |
| 1716 | if crdErr != nil { |
| 1717 | c.logger.Warn(c.ctx, "failed to close remote coordination", slog.Error(crdErr)) |
| 1718 | } |
| 1719 | case err := <-coordination.Wait(): |
| 1720 | if err != nil && |
| 1721 | !xerrors.Is(err, io.EOF) && |
| 1722 | !xerrors.Is(err, context.Canceled) && |
| 1723 | !xerrors.Is(err, context.DeadlineExceeded) { |
| 1724 | c.logger.Error(c.ctx, "remote coordination error", slog.Error(err)) |
| 1725 | } |
| 1726 | } |
| 1727 | } |
| 1728 | |
| 1729 | func (c *Controller) derpMap(client DERPClient) error { |
| 1730 | defer func() { |