handleError inspects errors and terminates if the errors are non-recoverable. A gRPC code is Internal if there is an unforeseen issue that needs attention. A gRPC code is Unavailable when we can't possibly reach the remote server, most likely the server expects TLS and our certificate does not match
(err error, isRetry bool)
| 102 | // the node certificate is created the name much match the request host name. e.g., localhost not |
| 103 | // 127.0.0.1. |
| 104 | func handleError(err error, isRetry bool) { |
| 105 | s := status.Convert(err) |
| 106 | switch { |
| 107 | case s.Code() == codes.Internal, s.Code() == codes.Unavailable: |
| 108 | // Let us not crash live loader due to this. Instead, we should infinitely retry to |
| 109 | // reconnect and retry the request. |
| 110 | //nolint:gosec // random generator in closed set does not require cryptographic precision |
| 111 | dur := time.Duration(1+rand.Intn(60)) * time.Second |
| 112 | fmt.Printf("Connection has been possibly interrupted. Got error: %v."+ |
| 113 | " Will retry after %s.\n", err, dur.Round(time.Second)) |
| 114 | time.Sleep(dur) |
| 115 | case strings.Contains(s.Message(), "x509"): |
| 116 | x.Fatalf("%v", s.Message()) |
| 117 | case s.Code() == codes.Aborted: |
| 118 | if !isRetry && opt.verbose { |
| 119 | fmt.Printf("Transaction aborted. Will retry in background.\n") |
| 120 | } |
| 121 | case strings.Contains(s.Message(), "Server overloaded."): |
| 122 | //nolint:gosec // random generator in closed set does not require cryptographic precision |
| 123 | dur := time.Duration(1+rand.Intn(10)) * time.Minute |
| 124 | fmt.Printf("Server is overloaded. Will retry after %s.\n", dur.Round(time.Minute)) |
| 125 | time.Sleep(dur) |
| 126 | case err != x.ErrConflict && err != dgo.ErrAborted: |
| 127 | fmt.Printf("Error while mutating: %v s.Code %v\n", s.Message(), s.Code()) |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | func (l *loader) infinitelyRetry(req *request) { |
| 132 | defer l.retryRequestsWg.Done() |
no test coverage detected
searching dependent graphs…