From a44e8dc94bcd137c22c3b2f3b7bb7ac6aba269f9 Mon Sep 17 00:00:00 2001 From: DarthSim Date: Thu, 23 Jun 2022 17:23:04 +0600 Subject: [PATCH] Check timeout automatically --- processing/apply_filters.go | 4 ++-- processing/copy_and_check_timeout.go | 14 -------------- processing/finalize.go | 2 +- processing/fix_webp_size.go | 2 +- processing/pipeline.go | 2 ++ processing/processing.go | 6 +----- processing/scale.go | 2 +- processing/trim.go | 2 +- 8 files changed, 9 insertions(+), 25 deletions(-) delete mode 100644 processing/copy_and_check_timeout.go diff --git a/processing/apply_filters.go b/processing/apply_filters.go index 4eb487d1..c0c89fb0 100644 --- a/processing/apply_filters.go +++ b/processing/apply_filters.go @@ -12,7 +12,7 @@ func applyFilters(pctx *pipelineContext, img *vips.Image, po *options.Processing return nil } - if err := copyMemoryAndCheckTimeout(pctx.ctx, img); err != nil { + if err := img.CopyMemory(); err != nil { return err } @@ -52,5 +52,5 @@ func applyFilters(pctx *pipelineContext, img *vips.Image, po *options.Processing return err } - return copyMemoryAndCheckTimeout(pctx.ctx, img) + return img.CopyMemory() } diff --git a/processing/copy_and_check_timeout.go b/processing/copy_and_check_timeout.go deleted file mode 100644 index 15880962..00000000 --- a/processing/copy_and_check_timeout.go +++ /dev/null @@ -1,14 +0,0 @@ -package processing - -import ( - "context" - - "github.com/imgproxy/imgproxy/v3/router" - "github.com/imgproxy/imgproxy/v3/vips" -) - -func copyMemoryAndCheckTimeout(ctx context.Context, img *vips.Image) error { - err := img.CopyMemory() - router.CheckTimeout(ctx) - return err -} diff --git a/processing/finalize.go b/processing/finalize.go index ba574ca1..0dd65b4c 100644 --- a/processing/finalize.go +++ b/processing/finalize.go @@ -106,5 +106,5 @@ func finalize(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOpti } } - return copyMemoryAndCheckTimeout(pctx.ctx, img) + return img.CopyMemory() } diff --git a/processing/fix_webp_size.go b/processing/fix_webp_size.go index 83ca6929..b352a374 100644 --- a/processing/fix_webp_size.go +++ b/processing/fix_webp_size.go @@ -29,5 +29,5 @@ func fixWebpSize(pctx *pipelineContext, img *vips.Image, po *options.ProcessingO log.Warningf("WebP dimension size is limited to %d. The image is rescaled to %dx%d", int(webpMaxDimension), img.Width(), img.Height()) - return copyMemoryAndCheckTimeout(pctx.ctx, img) + return img.CopyMemory() } diff --git a/processing/pipeline.go b/processing/pipeline.go index aac52f01..a9756630 100644 --- a/processing/pipeline.go +++ b/processing/pipeline.go @@ -6,6 +6,7 @@ import ( "github.com/imgproxy/imgproxy/v3/imagedata" "github.com/imgproxy/imgproxy/v3/imagetype" "github.com/imgproxy/imgproxy/v3/options" + "github.com/imgproxy/imgproxy/v3/router" "github.com/imgproxy/imgproxy/v3/vips" ) @@ -52,6 +53,7 @@ func (p pipeline) Run(ctx context.Context, img *vips.Image, po *options.Processi if err := step(&pctx, img, po, imgdata); err != nil { return err } + router.CheckTimeout(ctx) } return nil diff --git a/processing/processing.go b/processing/processing.go index 22cd7ccd..cca1f6c7 100644 --- a/processing/processing.go +++ b/processing/processing.go @@ -140,7 +140,7 @@ func transformAnimated(ctx context.Context, img *vips.Image, po *options.Process return err } - if err = copyMemoryAndCheckTimeout(ctx, img); err != nil { + if err = img.CopyMemory(); err != nil { return err } @@ -264,10 +264,6 @@ func ProcessImage(ctx context.Context, imgdata *imagedata.ImageData, po *options } } - if err := copyMemoryAndCheckTimeout(ctx, img); err != nil { - return nil, err - } - if po.Format == imagetype.AVIF && (img.Width() < 16 || img.Height() < 16) { if img.HasAlpha() { po.Format = imagetype.PNG diff --git a/processing/scale.go b/processing/scale.go index 12b73dac..6fa245ef 100644 --- a/processing/scale.go +++ b/processing/scale.go @@ -18,5 +18,5 @@ func scale(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions } } - return copyMemoryAndCheckTimeout(pctx.ctx, img) + return img.CopyMemory() } diff --git a/processing/trim.go b/processing/trim.go index bad7cddd..042e1f95 100644 --- a/processing/trim.go +++ b/processing/trim.go @@ -14,7 +14,7 @@ func trim(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions, if err := img.Trim(po.Trim.Threshold, po.Trim.Smart, po.Trim.Color, po.Trim.EqualHor, po.Trim.EqualVer); err != nil { return err } - if err := copyMemoryAndCheckTimeout(pctx.ctx, img); err != nil { + if err := img.CopyMemory(); err != nil { return err }