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> // Kirill Smelkov <kirr@nexedi.com>
// //
// This program is free software: you can Use, Study, Modify and Redistribute // This program is free software: you can Use, Study, Modify and Redistribute
...@@ -26,6 +26,7 @@ package xcontext ...@@ -26,6 +26,7 @@ package xcontext
import ( import (
"context" "context"
"errors"
) )
// Cancelled reports whether an error is due to a canceled context. // Cancelled reports whether an error is due to a canceled context.
...@@ -35,11 +36,14 @@ import ( ...@@ -35,11 +36,14 @@ import (
// Canceled treats both context.Canceled and context.DeadlineExceeded as errors // Canceled treats both context.Canceled and context.DeadlineExceeded as errors
// indicating context cancellation. // indicating context cancellation.
func Canceled(err error) bool { func Canceled(err error) bool {
switch err { switch {
case context.Canceled, context.DeadlineExceeded: case err == nil:
return false
case errors.Is(err, context.Canceled):
return true
case errors.Is(err, context.DeadlineExceeded):
return true return true
} }
return false return false
} }
......
...@@ -701,7 +701,7 @@ func openClientByURL(ctx context.Context, u *url.URL, opt *zodb.DriverOptions) ( ...@@ -701,7 +701,7 @@ func openClientByURL(ctx context.Context, u *url.URL, opt *zodb.DriverOptions) (
err := c.Run(context.Background()) // NOTE not ctx err := c.Run(context.Background()) // NOTE not ctx
// Client.Close cancels talkMaster which makes Run to return // Client.Close cancels talkMaster which makes Run to return
// `client: talk master(M): context canceled` // `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) { if errors.Is(err, context.Canceled) {
err = nil err = nil
} }
......
...@@ -29,8 +29,6 @@ import ( ...@@ -29,8 +29,6 @@ import (
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
"github.com/pkg/errors"
"lab.nexedi.com/kirr/go123/xnet" "lab.nexedi.com/kirr/go123/xnet"
"lab.nexedi.com/kirr/neo/go/neo/neonet" "lab.nexedi.com/kirr/neo/go/neo/neonet"
...@@ -349,7 +347,7 @@ loop: ...@@ -349,7 +347,7 @@ loop:
if r.err != nil { if r.err != nil {
log.Error(ctx, r.err) log.Error(ctx, r.err)
if !xcontext.Canceled(errors.Cause(r.err)) { if !xcontext.Canceled(r.err) {
r.stor.CloseLink(ctx) r.stor.CloseLink(ctx)
r.stor.SetState(proto.DOWN) r.stor.SetState(proto.DOWN)
} }
...@@ -433,7 +431,7 @@ loop2: ...@@ -433,7 +431,7 @@ loop2:
// XXX dup wrt <-recovery handler above // XXX dup wrt <-recovery handler above
log.Error(ctx, r.err) log.Error(ctx, r.err)
if !xcontext.Canceled(errors.Cause(r.err)) { if !xcontext.Canceled(r.err) {
r.stor.CloseLink(ctx) r.stor.CloseLink(ctx)
r.stor.SetState(proto.DOWN) r.stor.SetState(proto.DOWN)
} }
...@@ -608,7 +606,7 @@ loop: ...@@ -608,7 +606,7 @@ loop:
if v.err != nil { if v.err != nil {
log.Error(ctx, v.err) log.Error(ctx, v.err)
if !xcontext.Canceled(errors.Cause(v.err)) { if !xcontext.Canceled(v.err) {
v.stor.CloseLink(ctx) v.stor.CloseLink(ctx)
v.stor.SetState(proto.DOWN) v.stor.SetState(proto.DOWN)
} }
...@@ -657,7 +655,7 @@ loop2: ...@@ -657,7 +655,7 @@ loop2:
// XXX dup wrt <-verify handler above // XXX dup wrt <-verify handler above
log.Error(ctx, v.err) log.Error(ctx, v.err)
if !xcontext.Canceled(errors.Cause(v.err)) { if !xcontext.Canceled(v.err) {
v.stor.CloseLink(ctx) v.stor.CloseLink(ctx)
v.stor.SetState(proto.DOWN) 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