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

Image thumbs: persisting jobs files #6511

Open
nilshoerrmann opened this issue Jun 27, 2024 · 5 comments
Open

Image thumbs: persisting jobs files #6511

nilshoerrmann opened this issue Jun 27, 2024 · 5 comments
Labels
needs: replication 🔬 Requires a sample to reproduce the issue

Comments

@nilshoerrmann
Copy link
Contributor

Description

On a website with many images we noticed a lot of image job files persisted even after the thumbnails had been created.

Expected behavior
Jobs should be removed after processing.

Screenshots
grafik

Your setup

Kirby Version
Kirby 4.2

@afbora
Copy link
Member

afbora commented Jun 27, 2024

I've done few tests but I couldn't reproduce the issue. May be race condition? I think, it could be reproducible with multiple concurrent same requests.

@nilshoerrmann
Copy link
Contributor Author

I've noticed this on different servers (production and localhost) and with different image sizes (small and large). We have this custom code to generate small image thumbs we use as placeholders:

    public function previewUri()
    {
        try {
            [$width, $height] = $this->dimensions();
            $height = round((65 / $width) * $height);
            $width = 65;

            if ($this->crop) {
                $options = null;

                if ($this->crop !== 'focus') {
                    $options = [
                        'crop' => $this->crop
                    ];
                }

                $thumb = $this->file->crop($width, $height, $options);
            } else {
                $thumb = $this->file->thumb([
                    'width' => $width,
                    'height' => $height
                ]);
            }

            if (!$thumb->exists()) {
                $thumb->save();
            }

            return F::uri($thumb->root());
        } catch (Exception $e) {
            return '';
        }
    }

Not sure if this might be a source of this issue, too. Still, the persistent job files do not only affect these thumbs but other images as well.

@nilshoerrmann
Copy link
Contributor Author

I also noticed that sometimes there are just unchanged copies of the original image in the media folder (same file size, same dimensions):

grafik

We are also seeing high CPU usage and failures. Although we are using GD for image creation, this might be related to #5328.

@afbora
Copy link
Member

afbora commented Jun 30, 2024

I also noticed that sometimes there are just unchanged copies of the original image in the media folder (same file size, same dimensions):

I'm pretty sure that you already know this, but I think you may have overlooked it. This behavior is possible if the original image is used in the content or a original url is provided for the lightbox (as in the example below). Of course, I'm making an assumption since I don't know your case. In the example below, the original image is not copied to the media folder unless the lightbox is running to enlarge the image.

<a href="<?= $cover->url() ?>" data-lightbox class="img">
  <img src="<?= $cover->crop(1200, 600)->url() ?>" alt="<?= $cover->alt()->esc() ?>">
</a>

@nilshoerrmann
Copy link
Contributor Author

nilshoerrmann commented Jul 1, 2024

@afbora You are right about the directly linked sources (and you are totally right, that I overlooked that, too). So this is just fine 👍

We are still left with the persisting job files. My guess is something did not work as expected while generating thumbs. Let this either be a memory or CPU limit or some kind of other fault on the server. So do coexisting job and thumb files imply that something is wrong with the generated thumb? Let's say the thumb is only partly rendered. This is an important question because if this is the case, the thumb should be regenerated on next call, discarding the existing thumb. But this could cause more trouble if the server was already at its limits forcing recursive image generations. If – on the other hand – an existing thumb predicates that the image generation finished correctly (because it was only moved from tmp to the media folder after generation, I don't know), then the persisting job file could savely be removed on second call.

The question is which is right and which is wrong: the existing job or image files?

@afbora afbora added needs: replication 🔬 Requires a sample to reproduce the issue labels Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: replication 🔬 Requires a sample to reproduce the issue
Projects
None yet
Development

No branches or pull requests

2 participants