Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancelling image transformation #71

Closed
patt1s0n opened this issue Apr 1, 2020 · 2 comments
Closed

Cancelling image transformation #71

patt1s0n opened this issue Apr 1, 2020 · 2 comments

Comments

@patt1s0n
Copy link

patt1s0n commented Apr 1, 2020

Sometimes we have very large images which take a long time to transform; we'd like to be able to cancel the transformation if a time limit is reached.

I've tried implementing this using time.After and running the image transformation in a separate goroutine. Then cancelling the goroutine if the timeout is reached; however this causes a runtime error:

fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30d pc=0x7fff639a9d82]

runtime stack:
runtime.throw(0x4fec013, 0x2a)
        /usr/local/Cellar/go/1.13.3/libexec/src/runtime/panic.go:774 +0x72
runtime.sigpanic()
        /usr/local/Cellar/go/1.13.3/libexec/src/runtime/signal_unix.go:378 +0x47c

goroutine 83 [syscall]:
runtime.cgocall(0x44eed90, 0xc00027cdb8, 0xc00011d340)
        /usr/local/Cellar/go/1.13.3/libexec/src/runtime/cgocall.go:128 +0x5b fp=0xc00027cd88 sp=0xc00027cd50 pc=0x4004bdb
github.com/discordapp/lilliput._Cfunc_giflib_decoder_decode_frame_header(0x8b003e0, 0x0)
        _cgo_gotypes.go:303 +0x49 fp=0xc00027cdb8 sp=0xc00027cd88 pc=0x43e6229

Is there a graceful way to cancel a call to ImageOps.Transform?

@brian-armstrong-discord
Copy link
Contributor

Hello,

No, I don't think that will be possible. The work is taking place in CGo and is performing computations until it completes, so there isn't any way to get its attention, so to speak. Your best bet is probably to use the header methods to inspect the dimensions and decide whether to proceed before starting the transform.

@patt1s0n
Copy link
Author

patt1s0n commented Apr 2, 2020

Okay cheers for the response.

@patt1s0n patt1s0n closed this as completed Apr 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants