mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-02-07 03:09:44 +03:00
GIF Thumbnail creation fails, breaking the image picker window #4793
Closed
opened 2026-02-05 09:16:01 +03:00 by OVERLORD
·
12 comments
No Branch/Tag Specified
development
further_theme_development
l10n_development
release
llm_only
vectors
v25-11
docker_env
drawio_rendering
user_permissions
ldap_host_failover
svg_image
prosemirror
captcha_example
fix/video-export
v25.12.3
v25.12.2
v25.12.1
v25.12
v25.11.6
v25.11.5
v25.11.4
v24.11.4
v25.11.3
v25.11.2
v25.11.1
v25.11
v25.07.3
v25.07.2
v25.07.1
v25.07
v25.05.2
v25.05.1
v25.05
v25.02.5
v25.02.4
v25.02.3
v25.02.2
v25.02.1
v25.02
v24.12.1
v24.12
v24.10.3
v24.10.2
v24.10.1
v24.10
v24.05.4
v24.05.3
v24.05.2
v24.05.1
v24.05
v24.02.3
v24.02.2
v24.02.1
v24.02
v23.12.3
v23.12.2
v23.12.1
v23.12
v23.10.4
v23.10.3
v23.10.2
v23.10.1
v23.10
v23.08.3
v23.08.2
v23.08.1
v23.08
v23.06.2
v23.06.1
v23.06
v23.05.2
v23.05.1
v23.05
v23.02.3
v23.02.2
v23.02.1
v23.02
v23.01.1
v23.01
v22.11.1
v22.11
v22.10.2
v22.10.1
v22.10
v22.09.1
v22.09
v22.07.3
v22.07.2
v22.07.1
v22.07
v22.06.2
v22.06.1
v22.06
v22.04.2
v22.04.1
v22.04
v22.03.1
v22.03
v22.02.3
v22.02.2
v22.02.1
v22.02
v21.12.5
v21.12.4
v21.12.3
v21.12.2
v21.12.1
v21.12
v21.11.3
v21.11.2
v21.11.1
v21.11
v21.10.3
v21.10.2
v21.10.1
v21.10
v21.08.6
v21.08.5
v21.08.4
v21.08.3
v21.08.2
v21.08.1
v21.08
v21.05.4
v21.05.3
v21.05.2
v21.05.1
v21.05
v21.04.6
v21.04.5
v21.04.4
v21.04.3
v21.04.2
v21.04.1
v21.04
v0.31.8
v0.31.7
v0.31.6
v0.31.5
v0.31.4
v0.31.3
v0.31.2
v0.31.1
v0.31.0
v0.30.7
v0.30.6
v0.30.5
v0.30.4
v0.30.3
v0.30.2
v0.30.1
v0.30.0
v0.29.3
v0.29.2
v0.29.1
v0.29.0
v0.28.3
v0.28.2
v0.28.1
v0.28.0
v0.27.5
v0.27.4
v0.27.3
v0.27.2
v0.27.1
v0.27
v0.26.4
v0.26.3
v0.26.2
v0.26.1
v0.26.0
v0.25.5
v0.25.4
v0.25.3
v0.25.2
v0.25.1
v0.25.0
v0.24.3
v0.24.2
v0.24.1
v0.24.0
v0.23.2
v0.23.1
v0.23.0
v0.22.0
v0.21.0
v0.20.3
v0.20.2
v0.20.1
v0.20.0
v0.19.0
v0.18.5
v0.18.4
v0.18.3
v0.18.2
v0.18.1
v0.18.0
v0.17.4
v0.17.3
v0.17.2
v0.17.1
v0.17.0
v0.16.3
v0.16.2
v0.16.1
v0.16.0
v0.15.3
v0.15.2
v0.15.1
v0.15.0
v0.14.3
v0.14.2
v0.14.1
v0.14.0
v0.13.1
v0.13.0
v0.12.2
v0.12.1
v0.12.0
v0.11.2
v0.11.1
v0.11.0
v0.10.0
v0.9.3
v0.9.2
v0.9.1
v0.9.0
v0.8.2
v0.8.1
v0.8.0
v0.7.6
v0.7.5
v0.7.4
v0.7.3
0.7.2
v.0.7.1
v0.7.0
v0.6.3
v0.6.2
v0.6.1
v0.6.0
v0.5.0
Labels
Clear labels
🎨 Design
📖 Docs Update
🐛 Bug
🐛 Bug
:cat2:🐈 Possible duplicate
💿 Database
☕ Open to discussion
💻 Front-End
🐕 Support
🚪 Authentication
🌍 Translations
🔌 API Task
🏭 Back-End
⛲ Upstream
🔨 Feature Request
🛠️ Enhancement
🛠️ Enhancement
🛠️ Enhancement
❤️ Happy feedback
🔒 Security
🔍 Pending Validation
💆 UX
📝 WYSIWYG Editor
🌔 Out of scope
🔩 API Request
:octocat: Admin/Meta
🖌️ View Customization
❓ Question
🚀 Priority
🛡️ Blocked
🚚 Export System
♿ A11y
🔧 Maintenance
> Markdown Editor
pull-request
Mirrored from GitHub Pull Request
Milestone
No items
No Milestone
Projects
Clear projects
No project
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: starred/BookStack#4793
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @bytebone on GitHub (May 23, 2024).
Describe the Bug
When uploading a gif, Bookstack often fails to extract/generate a thumbnail image. This is not communicated in the GUI or the realtime application logs. But it is visible on the filesystem, where the original file is saved, but no thumbnail gets created in the respective subfolder, and an error gets logged in the laravel.log file (see below).
Once this has happened, the image picker no longer loads any images and gets stuck on an infinite loading animation. In the dev panel, after about a second of the image picker being open, the gallery endpoint returns a 502 error code.
To resolve the issue, the original gif file needs to be deleted from the uploads folder. The image picker will load again and display a broken image item, which can then be deleted from the picker/database.
Steps to Reproduce
Expected Behaviour
Should be obvious
Screenshots or Additional Context
I am using the Linuxserver Docker image to run Bookstack, but by the nature of the error assume that its not an issue with their Docker wrapper, but with the core app.
Error Log:
Details
Browser Details
Brave 1.64.113 / Safari (Version unknown)
Exact BookStack Version
v24.05.1
@kalebalebachew commented on GitHub (May 23, 2024):
I've submitted a pull request that tries to fix it on #5030
@ssddanbrown commented on GitHub (May 23, 2024):
Hi @bytebone,
@bytebone commented on GitHub (May 23, 2024):
Hey Dan,
thanks for the prompt reply.
[Warning] Aborted connection 492 to db: 'bookstackapp' user: 'bookstack' host: '172.28.0.3' (Got an error reading communication packets)and from the nginx error log
349#349: *1023 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 172.19.0.4, server: _, request: "POST /images/gallery HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "wiki.mydomain.com", referrer: "https://wiki.mydomain.com/books/tisax-prep-ca-wip/draft/108"Heres a quick list of gifs that I tested:
(linked above)
I cannot see a specific pattern in these results. I'm curious to hear your opinion. If you have an idea where else I could find more helpful error logs, let me know.
In hindsight, I also want to note that we've upgrade from 23.12.2 straight to the newest 24.5.1. GIF upload has not been an issue on 23.12.2 as far as I can remember. Since I cannot bear the dataloss from a database rollback (lots of edits since the upgrade), I am unable to go back to that working version.
@ssddanbrown commented on GitHub (May 23, 2024):
Thanks for the info @bytebone,
Looking just at the difference between the working earth GIF and the provided drippy zig-zag gif, although a similar filesize and dimensions, the latter appears more complex. Opening in GIMP (as a rough test) the drippy zig-zag is 215 frames at 200MB of memory overall vs the earth having 44 frames at 8MB of memory.
Therefore I think this may be a memory exhaustion scenario during resize attempt.
Within the
php/php-local.inifile that's in the folder you have mounted at/configfor the app container, addmemory_limit=256Mthe save, then restart the app container.See if that makes a difference (Maybe try doubling again to 512M if it does not).
@bytebone commented on GitHub (May 24, 2024):
Interesting. After setting it to 512M, some of the formerly failing gifs can now be uploaded, but still not all. When trying to upload the 41.gif from above, i see a notable spike in CPU and RAM usage while BookStack attempts to extract a thumbnail, but after ~2.3 seconds I still get the 502 error response with the same behaviour as before. After doubling yet again to 1024M (equal to half of the total RAM on this small VPS) the 41.gif is still too complex for the thumbnail extractor. I can see the RAM filling up roughly by 1 GB - as soon as it does, the BookStack task fails and the issues continue as seen before.
How can the extractor require over a gigabyte of RAM when working with a 900 MB gif?
By doing this testing, I've found that the error flow described before only applies when the memory_limit is filled without hitting the machines RAM limit. With a memory_limit of 1024M, the machines RAM is full before (or at the same time as) the PHP limit, leading to the following flow:
@ssddanbrown commented on GitHub (May 24, 2024):
On my dev instance that I'm testing on there's a PHP
memory_limitof512M.This is on a strong 16 thread system though. Testing on my smaller test virtual instances, they appeared to lock up in CPU/memory usage using this gif.
I think this GIF is particularly problematic due to the sheer amount of frames (over 200) at reasonable resolution.
Looking into the library we use and PHP itself, the native PHP gd-based image handling lacks support for animated gifs, so these are managed via a combination of PHP-based encoder to manage the animation frames backed by native PHP gd render functions to do the manipulation work. Therefore this is like resize 200 images in one go (and then I'm guessing some likley heavy interpolation & compression steps afterwards). The PHP gd functions can use more memory than the PHP-based limit, and I wouldn't be surprised if this GIF finds some edge-case memory leaks in this process.
Whatever's going on here, it's probably more sensible if we avoid handling animation during this process and instead just create a thumbnail based upon a single frame.
I think this is what used to happen when we originally added GIF support, but the library we use added animation support since.
@bytebone commented on GitHub (May 25, 2024):
I fully agree, and since its only a preview for the image picker (presumably the gif gets natively rendered by the browser whenever its shown, without the need for processing by bookstack) IMO its perfectly fine to take the first frame of the gif and pull that out as the thumbnail.
Right now I cannot really tell if this is something you'd consider fixing soon-ish or some time later down the road. If this isn't important enough in the grander scheme to fix quickly, do you think some better error handling could be done in an update soon, so that the app doesn't behave so crazily whenever it happens? Having to dig around in the filesystem whenever a gif fails to generate a thumbnail gets tedious over time...
@ssddanbrown commented on GitHub (May 25, 2024):
I'll assign to the next patch milestone. No time assurance for when that would be but should not be too far in the future.
Gracefully dealing with these types of scenerios can get fairly tricky, as it's going to depend quite significantly on environment and often we lack control in these events (PHP process jammed or OS kills the process). It'll be easier & less complex for us to make the change.
@jacobslutsky-blacksmith commented on GitHub (May 31, 2024):
Hello. I'm running into this issue with animated .gifs as well. The actual file size of the .gif is tiny, but it is also around 200 frames.
We currently have a VM with 4GB of RAM, running a PHP memory_limit of 256M.
Would you recommend increasing both the available RAM and the PHP memory_limit to say 1GB to get around this issue?
Or is there a patch for the single frame thumbnail generation?
Thanks.
@ssddanbrown commented on GitHub (Jun 9, 2024):
I've now updated our handling to only resize via native methods without animation support, via commit
3406846c82, with tests added to cover. This will be part of the next upcoming patch release so I'll therefore close this off.@bytebone commented on GitHub (Jun 10, 2024):
Just tested the newest release, reset the memory limit by commenting out the added line (assuming the default is 256M), and uploaded the GIF that broke everything earlier, as well as a huge 9 MB gif. Both work very fast, instantly displaying in the document and image picker. Great work, thank you very much for the fast assistance and fix.
@jacobslutsky-blacksmith commented on GitHub (Jun 11, 2024):
Much thanks @ssddanbrown
We are using the latest release as well and all GIF's that previously caused the error are not doing so anymore.
Very nice.