Commit 40cba436 authored by Kirill Smelkov's avatar Kirill Smelkov

X Fix xcontext.Canceled to verify cancellation for error chains

previously

- we were explicitly calling it on errors.Cause(err)
- and not in every place.
parent 0f7357ec
// Copyright (C) 2017-2018 Nexedi SA and Contributors.
// Copyright (C) 2017-2020 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
......@@ -26,6 +26,7 @@ package xcontext
import (
"context"
"errors"
)
// Cancelled reports whether an error is due to a canceled context.
......@@ -35,11 +36,14 @@ import (
// Canceled treats both context.Canceled and context.DeadlineExceeded as errors
// indicating context cancellation.
func Canceled(err error) bool {
switch err {
case context.Canceled, context.DeadlineExceeded:
switch {
case err == nil:
return false
case errors.Is(err, context.Canceled):
return true
case errors.Is(err, context.DeadlineExceeded):
return true
}
return false
}
......
......@@ -701,7 +701,7 @@ func openClientByURL(ctx context.Context, u *url.URL, opt *zodb.DriverOptions) (
err := c.Run(context.Background()) // NOTE not ctx
// Client.Close cancels talkMaster which makes Run to return
// `client: talk master(M): context canceled`
// do not propagate this error ZODB-level user.
// do not propagate this error to ZODB-level user.
if errors.Is(err, context.Canceled) {
err = nil
}
......
......@@ -29,8 +29,6 @@ import (
"golang.org/x/sync/errgroup"
"github.com/pkg/errors"
"lab.nexedi.com/kirr/go123/xnet"
"lab.nexedi.com/kirr/neo/go/neo/neonet"
......@@ -349,7 +347,7 @@ loop:
if r.err != nil {
log.Error(ctx, r.err)
if !xcontext.Canceled(errors.Cause(r.err)) {
if !xcontext.Canceled(r.err) {
r.stor.CloseLink(ctx)
r.stor.SetState(proto.DOWN)
}
......@@ -433,7 +431,7 @@ loop2:
// XXX dup wrt <-recovery handler above
log.Error(ctx, r.err)
if !xcontext.Canceled(errors.Cause(r.err)) {
if !xcontext.Canceled(r.err) {
r.stor.CloseLink(ctx)
r.stor.SetState(proto.DOWN)
}
......@@ -608,7 +606,7 @@ loop:
if v.err != nil {
log.Error(ctx, v.err)
if !xcontext.Canceled(errors.Cause(v.err)) {
if !xcontext.Canceled(v.err) {
v.stor.CloseLink(ctx)
v.stor.SetState(proto.DOWN)
}
......@@ -657,7 +655,7 @@ loop2:
// XXX dup wrt <-verify handler above
log.Error(ctx, v.err)
if !xcontext.Canceled(errors.Cause(v.err)) {
if !xcontext.Canceled(v.err) {
v.stor.CloseLink(ctx)
v.stor.SetState(proto.DOWN)
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment