SerenityOS / serenity

The Serenity Operating System 🐞
https://serenityos.org
BSD 2-Clause "Simplified" License
30.73k stars 3.19k forks source link

Ladybird: "Too many open files" in ImageDecoder when visiting Berkeley Mono website #22892

Open awesomekling opened 10 months ago

awesomekling commented 10 months ago

To reproduce, open https://berkeleygraphics.com/typefaces/berkeley-mono/

After a short time, this error shows up:

342154.967 ImageDecoder(1431722): IPC::ConnectionBase::handle_messages: dup: Too many open files (errno=24)

There's a pretty huge GIF animation with 708(!) frames on the page, seems likely to be related :sweat_smile:

ADKaster commented 10 months ago

As mentioned on discord, we apparently create a separate memfd-backed anonymous buffer for each frame of animated gifs when interacting with ImageDecoder.

https://github.com/SerenityOS/serenity/blob/333454456b9150d9efb8697d6d314bb5a6a06108/Userland/Services/ImageDecoder/ImageDecoderServer.ipc#L6

With a 708 frame gif, that means we create 708 file descriptors, just for the one gif on the page. It's not surprising we hit the per-process fd limit that way.

We should refactor the way Gifs or other animated image formats are handled in ImageDecoder to not use so many dang file descriptors.

nico commented 10 months ago

Isn't the ulimit for fds on Linux many thousands?

ADKaster commented 10 months ago

In a bash session on my ubuntu 22.04 machine, it's 1024

$ ulimit -n
1024
nico commented 10 months ago

That's the soft limit though. Could setrlimit that up by 10x as a short-term fix :)

ADKaster commented 7 months ago

With the merging of https://github.com/SerenityOS/serenity/pull/24025 this issue becomes a bit more pressing. The current max number of fds that can be transferred at a time is 64. This limits gifs to 64 frames. The absolute max on linux for SCM_RIGHTS fd passing is 253, according to the man pages.