MCPcopy Create free account
hub / github.com/dgraph-io/dgraph / handleError

Function handleError

dgraph/cmd/live/batch.go:104–129  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

102// the node certificate is created the name much match the request host name. e.g., localhost not
103// 127.0.0.1.
104func 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
131func (l *loader) infinitelyRetry(req *request) {
132 defer l.retryRequestsWg.Done()

Callers 2

infinitelyRetryMethod · 0.85
requestMethod · 0.85

Calls 2

FatalfFunction · 0.92
CodeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…