From d88da4cc88ee7276b5b160a3d20cb3b5bb0d56fe Mon Sep 17 00:00:00 2001 From: zjbztianya Date: Mon, 5 Apr 2021 21:20:35 +0800 Subject: [PATCH] Replace contextx.ShrinkDeadline with context.WithTimeout (#598) --- core/fx/timeout.go | 4 +--- zrpc/internal/clientinterceptors/timeoutinterceptor.go | 3 +-- zrpc/internal/serverinterceptors/timeoutinterceptor.go | 3 +-- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/core/fx/timeout.go b/core/fx/timeout.go index 33f70e8a..f8caec28 100644 --- a/core/fx/timeout.go +++ b/core/fx/timeout.go @@ -3,8 +3,6 @@ package fx import ( "context" "time" - - "github.com/tal-tech/go-zero/core/contextx" ) var ( @@ -23,7 +21,7 @@ func DoWithTimeout(fn func() error, timeout time.Duration, opts ...DoOption) err for _, opt := range opts { parentCtx = opt() } - ctx, cancel := contextx.ShrinkDeadline(parentCtx, timeout) + ctx, cancel := context.WithTimeout(parentCtx, timeout) defer cancel() // create channel with buffer size 1 to avoid goroutine leak diff --git a/zrpc/internal/clientinterceptors/timeoutinterceptor.go b/zrpc/internal/clientinterceptors/timeoutinterceptor.go index c27678ff..81cb88aa 100644 --- a/zrpc/internal/clientinterceptors/timeoutinterceptor.go +++ b/zrpc/internal/clientinterceptors/timeoutinterceptor.go @@ -4,7 +4,6 @@ import ( "context" "time" - "github.com/tal-tech/go-zero/core/contextx" "google.golang.org/grpc" ) @@ -16,7 +15,7 @@ func TimeoutInterceptor(timeout time.Duration) grpc.UnaryClientInterceptor { return invoker(ctx, method, req, reply, cc, opts...) } - ctx, cancel := contextx.ShrinkDeadline(ctx, timeout) + ctx, cancel := context.WithTimeout(ctx, timeout) defer cancel() // create channel with buffer size 1 to avoid goroutine leak diff --git a/zrpc/internal/serverinterceptors/timeoutinterceptor.go b/zrpc/internal/serverinterceptors/timeoutinterceptor.go index 8db1e9c8..c763b285 100644 --- a/zrpc/internal/serverinterceptors/timeoutinterceptor.go +++ b/zrpc/internal/serverinterceptors/timeoutinterceptor.go @@ -5,7 +5,6 @@ import ( "sync" "time" - "github.com/tal-tech/go-zero/core/contextx" "google.golang.org/grpc" ) @@ -13,7 +12,7 @@ import ( func UnaryTimeoutInterceptor(timeout time.Duration) grpc.UnaryServerInterceptor { return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { - ctx, cancel := contextx.ShrinkDeadline(ctx, timeout) + ctx, cancel := context.WithTimeout(ctx, timeout) defer cancel() var resp interface{}