From 6aeca54eced03f69609687c2af6523caf36d7375 Mon Sep 17 00:00:00 2001 From: jiuker <2818723467@qq.com> Date: Fri, 25 Aug 2023 22:58:38 +0800 Subject: [PATCH] fix: replace context by timeout-context from parent-context when `selfSpeedTest` (#17906) --- cmd/perf-tests.go | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/cmd/perf-tests.go b/cmd/perf-tests.go index 331c0784f..d4ddc1324 100644 --- a/cmd/perf-tests.go +++ b/cmd/perf-tests.go @@ -85,14 +85,9 @@ func selfSpeedTest(ctx context.Context, opts speedTestOpts) (SpeedTestResult, er objCountPerThread := make([]uint64, opts.concurrency) - uploadsCtx, uploadsCancel := context.WithCancel(context.Background()) + uploadsCtx, uploadsCancel := context.WithTimeout(ctx, opts.duration) defer uploadsCancel() - go func() { - time.Sleep(opts.duration) - uploadsCancel() - }() - objNamePrefix := pathJoin(speedTest, mustGetUUID()) userMetadata := make(map[string]string) @@ -144,12 +139,8 @@ func selfSpeedTest(ctx context.Context, opts speedTestOpts) (SpeedTestResult, er }, nil } - downloadsCtx, downloadsCancel := context.WithCancel(context.Background()) + downloadsCtx, downloadsCancel := context.WithTimeout(ctx, opts.duration) defer downloadsCancel() - go func() { - time.Sleep(opts.duration) - downloadsCancel() - }() gopts := minio.GetObjectOptions{} gopts.Set(globalObjectPerfUserMetadata, "true") // Bypass S3 API freeze