From ab1dc52a10c72a51eb160e3824a83f04f44c8651 Mon Sep 17 00:00:00 2001 From: Chris Schinnerl Date: Thu, 18 Apr 2024 10:19:16 +0200 Subject: [PATCH] all: update ctx.Err() usage to context.Cause(ctx) --- stores/metadata.go | 2 +- worker/download.go | 2 +- worker/host_test.go | 2 +- worker/pricetables.go | 2 +- worker/rhpv2.go | 4 ++-- worker/rhpv3.go | 2 +- worker/upload.go | 2 +- worker/worker.go | 4 ++-- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/stores/metadata.go b/stores/metadata.go index 56202ccf3..87a63c7bc 100644 --- a/stores/metadata.go +++ b/stores/metadata.go @@ -2050,7 +2050,7 @@ UPDATE objects SET health = ( } select { case <-ctx.Done(): - return ctx.Err() + return context.Cause(ctx) case <-time.After(time.Second): } } diff --git a/worker/download.go b/worker/download.go index 83d4bec3e..2e69f7375 100644 --- a/worker/download.go +++ b/worker/download.go @@ -731,7 +731,7 @@ loop: case <-s.mgr.shutdownCtx.Done(): return nil, false, errors.New("download stopped") case <-ctx.Done(): - return nil, false, ctx.Err() + return nil, false, context.Cause(ctx) case <-resps.c: resetOverdrive() } diff --git a/worker/host_test.go b/worker/host_test.go index dcc089154..cb88f1748 100644 --- a/worker/host_test.go +++ b/worker/host_test.go @@ -97,7 +97,7 @@ func (h *testHost) UploadSector(ctx context.Context, sectorRoot types.Hash256, s select { case <-time.After(h.uploadDelay): case <-ctx.Done(): - return ctx.Err() + return context.Cause(ctx) } } return nil diff --git a/worker/pricetables.go b/worker/pricetables.go index 9ca4b1541..c4c693e0a 100644 --- a/worker/pricetables.go +++ b/worker/pricetables.go @@ -137,7 +137,7 @@ func (p *priceTable) fetch(ctx context.Context, rev *types.FileContractRevision) } else if ongoing { select { case <-ctx.Done(): - return api.HostPriceTable{}, fmt.Errorf("%w; %w", errPriceTableUpdateTimedOut, ctx.Err()) + return api.HostPriceTable{}, fmt.Errorf("%w; %w", errPriceTableUpdateTimedOut, context.Cause(ctx)) case <-update.done: } return update.hpt, update.err diff --git a/worker/rhpv2.go b/worker/rhpv2.go index 7207b96fa..1a6bd3cfd 100644 --- a/worker/rhpv2.go +++ b/worker/rhpv2.go @@ -645,8 +645,8 @@ func (w *worker) withTransportV2(ctx context.Context, hostKey types.PublicKey, h }() defer func() { close(done) - if ctx.Err() != nil { - err = ctx.Err() + if context.Cause(ctx) != nil { + err = context.Cause(ctx) } }() t, err := rhpv2.NewRenterTransport(conn, hostKey) diff --git a/worker/rhpv3.go b/worker/rhpv3.go index 22b75adc3..dc483c340 100644 --- a/worker/rhpv3.go +++ b/worker/rhpv3.go @@ -237,7 +237,7 @@ func dialTransport(ctx context.Context, siamuxAddr string, hostKey types.PublicK case <-ctx.Done(): conn.Close() <-done - return nil, ctx.Err() + return nil, context.Cause(ctx) case <-done: return t, err } diff --git a/worker/upload.go b/worker/upload.go index 718d717ab..4a97099bb 100644 --- a/worker/upload.go +++ b/worker/upload.go @@ -873,7 +873,7 @@ loop: case <-u.shutdownCtx.Done(): return nil, 0, 0, ErrShuttingDown case <-ctx.Done(): - return nil, 0, 0, ctx.Err() + return nil, 0, 0, context.Cause(ctx) case resp := <-respChan: // receive the response used, done = slab.receive(resp) diff --git a/worker/worker.go b/worker/worker.go index cd3d545eb..60dfb475d 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -1431,7 +1431,7 @@ func (w *worker) scanHost(ctx context.Context, timeout time.Duration, hostKey ty // scan: second try select { case <-ctx.Done(): - return rhpv2.HostSettings{}, rhpv3.HostPriceTable{}, 0, ctx.Err() + return rhpv2.HostSettings{}, rhpv3.HostPriceTable{}, 0, context.Cause(ctx) case <-time.After(time.Second): } settings, pt, duration, err = scan() @@ -1449,7 +1449,7 @@ func (w *worker) scanHost(ctx context.Context, timeout time.Duration, hostKey ty // repercussions select { case <-ctx.Done(): - return rhpv2.HostSettings{}, rhpv3.HostPriceTable{}, 0, ctx.Err() + return rhpv2.HostSettings{}, rhpv3.HostPriceTable{}, 0, context.Cause(ctx) default: }