| 95 | } |
| 96 | |
| 97 | func initRPC(ctx context.Context, client *agentsdk.Client, l slog.Logger) (proto.DRPCAgentClient20, error) { |
| 98 | var c proto.DRPCAgentClient20 |
| 99 | var err error |
| 100 | retryCtx, retryCancel := context.WithTimeout(ctx, rpcConnectTimeout) |
| 101 | defer retryCancel() |
| 102 | attempts := 0 |
| 103 | for r := retry.New(100*time.Millisecond, time.Second); r.Wait(retryCtx); { |
| 104 | attempts++ |
| 105 | // Maximize compatibility. |
| 106 | c, err = client.ConnectRPC20(ctx) |
| 107 | if err != nil { |
| 108 | l.Debug(ctx, "Failed to connect to Coder", slog.F("error", err), slog.F("attempt", attempts)) |
| 109 | continue |
| 110 | } |
| 111 | break |
| 112 | } |
| 113 | if c == nil { |
| 114 | return nil, err |
| 115 | } |
| 116 | return proto.NewDRPCAgentClient(c.DRPCConn()), nil |
| 117 | } |
| 118 | |
| 119 | // sendLogsV1 uses the PatchLogs endpoint to send logs. |
| 120 | // This is deprecated, but required for backward compatibility with older versions of Coder. |