Using the golang client, dgo, I am trying to catch ErrAborted
errors and retry, as per instructions in the README: GitHub - dgraph-io/dgo: Official Dgraph Go client
In my application logs I am seeing a few errors like this: rpc error: code = Aborted desc = Transaction has been aborted. Please retry.
However, my retry code never gets called, leading me to think that y.ErrAborted
check is not working the way I expect from the docs. Is it returning the wrong error?
My code:
for i := 0; i < maxRetries; i++ {
_, err := dg.NewTxn().Mutate(ctx, mu)
if err != nil {
if err == y.ErrAborted {
// This never gets called
sleep := time.Duration(time.Duration(rand.Intn(10)) * time.Second)
logger.Warn("mutation aborted, retrying...", zap.Error(err), zap.Duration("retry-in", sleep), zap.Int("attempt", i))
time.Sleep(sleep)
} else {
logger.Error("error mutating graph", zap.Error(err), zap.Int("attempt", i))
break
}
} else {
// mutation was successful.
break
}
Thanks.