davidbyttow / govips

A lightning fast image processing and resizing library for Go
MIT License
1.29k stars 199 forks source link

composite a png over a jpg file,and then encode to avif, then failed and ”[VIPS.warning] Not a PNG file“ #447

Open g00302909 opened 2 months ago

g00302909 commented 2 months ago

I want do watermark handle。 And my operrateion is use a jpg as base file, and the overlay file is png。 When i do the operation by Composite api, it will failed, and report ”[VIPS.warning] Not a PNG file“。 the stack is under below:

Scene appears:if the server only one request, it's ok。 when the server is busy, which has multiple concurrent requests, then it will failed.

Please help me give some handle advice, thank you.

err="\nStack:\ngoroutine 5451 [running]:\nruntime/debug.Stack()\n\t/usr/local/go/src/runtime/debug/stack.go:24 +0x65\ngithub.com/davidbyttow/govips/v2/vips.handleVipsError()\n\t/var/lib/docker/columbus/repo/pkg_repo/2024082016/148556/45906816/1724141011449/src_repo/server/vendor/github.com/davidbyttow/govips/v2/vips/error.go:38 +0x57\ngithub.com/davidbyttow/govips/v2/vips.handleSaveBufferError(0xc00004a000?)\n\t/var/lib/docker/columbus/repo/pkg_repo/2024082016/148556/45906816/1724141011449/src_repo/server/vendor/github.com/davidbyttow/govips/v2/vips/error.go:31 +0x25\ngithub.com/davidbyttow/govips/v2/vips.vipsSaveToBuffer({0x7ff57e5f6e10, 0x0, 0xb, 0x0, 0x0, 0x2d, 0x0, 0x0, 0x1, 0x0, ...})\n\t/var/lib/docker/columbus/repo/pkg_repo/2024082016/148556/45906816/1724141011449/src_repo/server/vendor/github.com/davidbyttow/govips/v2/vips/foreign.go:520 +0xa5\ngithub.com/davidbyttow/govips/v2/vips.vipsSaveAVIFToBuffer(0x7ff57e5f6e10, {0x0, 0x2d, 0x0, 0x6, 0x5})\n\t/var/lib/docker/columbus/repo/pkg_repo/2024082016/148556/45906816/1724141011449/src_repo/server/vendor/github.com/davidbyttow/govips/v2/vips/foreign.go:487 +0x158\ngithub.com/davidbyttow/govips/v2/vips.(ImageRef).ExportAvif(0xc0001674f0, 0xc0001705d0?)\n\t/var/lib/docker/columbus/repo/pkg_repo/2024082016/148556/45906816/1724141011449/src_repo/server/vendor/github.com/davidbyttow/govips/v2/vips/image.go:994 +0xa5\ngithub.com/davidbyttow/govips/v2/vips.(ImageRef).Export(0xc0001674f0?, 0xc00059e000)\

tonimelisma commented 2 months ago

Looks like it's just saving to a buffer when there's an error. Could this be an out of memory issue or something similar?

g00302909 commented 2 months ago

Looks like it's just saving to a buffer when there's an error. Could this be an out of memory issue or something similar?

When the server doesn't have concurrent req, it will be ok. So if out of memory, single req will be alos failed, but it is not happend.

My step is: start a server, then a script do common req continuously:such as only do webp export。 And then a req for watermark continuously, then fail will happend quickly.

g00302909 commented 2 months ago

I have a try to avoid and reduce probability of the problem.

Origin Step: do concurrent req,has a high probability of problem occurrence 1 one jpg, a png which is for watermark 2 do resize and crop 3 do watermark 4 export webp or avif will fail

avoidance plan step: 1 one jpg, a png which is for watermark 2 do resize and crop 3 export result to jpg, and reload the jpg 4 do watermark 5 export webp or avif

I think,maybe the handle goroutine mem is too high, but i haven't no idea to find where the problem is.