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 · 6 comments
Open

Image thumbs: persisting jobs files #6511

nilshoerrmann opened this issue Jun 27, 2024 · 6 comments
Labels
needs: replication 🔬 Requires a sample to reproduce the issue type: stale 💤 Will be closed soon because there was no recent activity

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
@github-actions github-actions bot added the type: stale 💤 Will be closed soon because there was no recent activity label Sep 2, 2024
@getkirby getkirby deleted a comment from github-actions bot Sep 2, 2024
@distantnative distantnative removed the type: stale 💤 Will be closed soon because there was no recent activity label Sep 2, 2024
Copy link
Contributor

github-actions bot commented Nov 2, 2024

This issue has been marked as stale because it requires further input but has not seen activity in the past months. This is for us to prioritize issues that are still relevant and actionable. It will be closed if no further activity occurs within the next 15 days. If this issue is still relevant to you, please help us in gathering the necessary input.

@github-actions github-actions bot added the type: stale 💤 Will be closed soon because there was no recent activity label Nov 2, 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 type: stale 💤 Will be closed soon because there was no recent activity
Projects
None yet
Development

No branches or pull requests

3 participants