h2non / bimg

Go package for fast high-level image processing powered by libvips C library
https://pkg.go.dev/github.com/h2non/bimg?tab=doc
MIT License
2.68k stars 337 forks source link

Unable to save image (Not a PNG file) on concurrent requests #406

Open anantadwi13 opened 2 years ago

anantadwi13 commented 2 years ago

Hi, I have an issue when using this library for high concurrent requests. When I apply a watermark with multiple concurrent requests, It will return an error png2vips: unable to read source source or even vips2png: unable to write to target. I don't know whether the problem occurs in this library or libvips.

I have created a repository to reproduce this error. Perhaps you can help me to investigate it. Thank you.

Environment:

How to reproduce:

It will not return an error if I'm using one request or as large as the CPU core size at a time.

Example ``` # docker run --rm -it -e CONCURRENT_REQ=8 test-bimg process is starting queueing #0 done epoch #0 req # 1 done epoch #0 req # 7 done epoch #0 req # 2 done epoch #0 req # 0 done epoch #0 req # 6 done epoch #0 req # 4 done epoch #0 req # 5 done epoch #0 req # 3 queueing #1 done epoch #1 req # 5 done epoch #1 req # 0 done epoch #1 req # 7 done epoch #1 req # 6 done epoch #1 req # 1 done epoch #1 req # 4 done epoch #1 req # 3 done epoch #1 req # 2 queueing #2 done epoch #2 req # 1 done epoch #2 req # 4 done epoch #2 req # 5 done epoch #2 req # 3 done epoch #2 req # 6 done epoch #2 req # 7 done epoch #2 req # 2 done epoch #2 req # 0 queueing #3 done epoch #3 req # 3 done epoch #3 req # 0 done epoch #3 req # 4 done epoch #3 req # 7 done epoch #3 req # 1 done epoch #3 req # 6 done epoch #3 req # 5 done epoch #3 req # 2 queueing #4 done epoch #4 req # 5 done epoch #4 req # 6 done epoch #4 req # 0 done epoch #4 req # 2 done epoch #4 req # 4 done epoch #4 req # 1 done epoch #4 req # 7 done epoch #4 req # 3 queueing #5 done epoch #5 req # 3 done epoch #5 req # 1 done epoch #5 req # 0 done epoch #5 req # 4 done epoch #5 req # 5 done epoch #5 req # 6 done epoch #5 req # 2 done epoch #5 req # 7 queueing #6 done epoch #6 req # 1 done epoch #6 req # 0 done epoch #6 req # 4 done epoch #6 req # 3 done epoch #6 req # 6 done epoch #6 req # 5 done epoch #6 req # 7 done epoch #6 req # 2 queueing #7 done epoch #7 req # 3 done epoch #7 req # 5 done epoch #7 req # 0 done epoch #7 req # 6 done epoch #7 req # 1 done epoch #7 req # 4 done epoch #7 req # 2 done epoch #7 req # 7 queueing #8 done epoch #8 req # 1 done epoch #8 req # 6 done epoch #8 req # 5 done epoch #8 req # 4 done epoch #8 req # 3 done epoch #8 req # 0 done epoch #8 req # 2 done epoch #8 req # 7 queueing #9 done epoch #9 req # 6 done epoch #9 req # 2 done epoch #9 req # 0 done epoch #9 req # 3 done epoch #9 req # 1 done epoch #9 req # 5 done epoch #9 req # 4 done epoch #9 req # 7 waiting for all requests process is done ```
anantadwi13 commented 2 years ago

Update:

It will be ok if I'm using workers https://github.com/anantadwi13/test-bimg/tree/with-worker

git clone https://github.com/anantadwi13/test-bimg.git
cd test-bimg
git checkout with-worker

docker build -t test-bimg .
docker run --rm -it -e WORKER=8 test-bimg