PixyBlue / caddy-pixbooster

On-the-fly image conversion for maximal performances
GNU Lesser General Public License v2.1
0 stars 0 forks source link

pixbooster crash caddy #5

Open adammakowskidev opened 2 months ago

adammakowskidev commented 2 months ago

Hi The plugin looks promising, unfortunately it crashes the caddy :/.

After the first visit to the site, the CPU usage is 100% and after 5 seconds the caddy crashes and is not responding.

I build caddy with this plugins:

CGO_ENABLED=1 \
xcaddy build \
    --with github.com/dunglas/caddy-cbrotli \
    --with github.com/pberkel/caddy-storage-redis \
    --with github.com/PixyBlue/caddy-pixbooster

My config:

{
    storage redis {
        host 127.0.0.1
        port 6379
        db 0
        timeout 5
        key_prefix "caddy-ssl"
        tls_enabled false
        tls_insecure true
    }
}

(global-config) {
    encode zstd br gzip
    header /* {
        -Server
        Strict-Transport-Security max-age=31536000
        Cache-Control "public, max-age=604800, must-revalidate"
    }
}

domaintest.com {
    import global-config
    root ./usr/share/caddy
       route {
        pixbooster {
            avif {
                quality 65
                speed 7
            }
        }
    }
    file_server
}
taophp commented 2 months ago

Could you please add the debug key to your main section like this:

{
    debug
    storage redis {
        host 127.0.0.1
        port 6379
        db 0
        timeout 5
        key_prefix "caddy-ssl"
        tls_enabled false
        tls_insecure true
    }
}

restart caddy and copy/paste the log in a comment below?

Your issue seems related to the redis storage: I tried by myself your configuration, except the redis part (I do not use Redis for the moment), and it seems to work well. Could you make a try without it and, if the problem occurs again, post the log here again?

This command may help?

caddy redis repair --config /path/to/Caddyfile

Maybe the problem could be related to the content of the page. Please, try with an empty one. Does the problem occurs again?

If nothing helps, you may open an issue on the Caddy Storage Redis project (maybe @pberkel could help here).

adammakowskidev commented 2 months ago

Hi Removing redis-storage didn't do anything, still the same problem. Maybe I don't have some library needed on my ubuntu? I am using an ARM64 processor.

taophp commented 2 months ago

Oh. Could you try without CGO?

CGO_ENABLED=1 \
xcaddy build \
    --with github.com/dunglas/caddy-cbrotli \
    --with github.com/pberkel/caddy-storage-redis \
    --with github.com/PixyBlue/caddy-pixbooster

The only consequence should be to disable Webp output.

adammakowskidev commented 2 months ago

CGO_ENABLED=1 is required for github.com/dunglas/caddy-cbrotli

taophp commented 2 months ago

Just give a try without it, just to know? Anyway, please, provide a log output. Or try with nowebpoutput directive.

adammakowskidev commented 2 months ago

github.com/PixyBlue/caddy-pixbooster

/root/go/pkg/mod/github.com/!pixy!blue/caddy-pixbooster@v0.1.0/module-withoutcgo.go:21:4: p.CGOEnabled undefined (type Pixbooster has no field or method CGOEnabled, but does have cGOEnabled) /root/go/pkg/mod/github.com/!pixy!blue/caddy-pixbooster@v0.1.0/module-withoutcgo.go:24:40: undefined: ImgFormat /root/go/pkg/mod/github.com/!pixy!blue/caddy-pixbooster@v0.1.0/module-withoutcgo.go:25:40: undefined: ImgFormat /root/go/pkg/mod/github.com/!pixy!blue/caddy-pixbooster@v0.1.0/module-withoutcgo.go:26:38: undefined: ImgFormat /root/go/pkg/mod/github.com/!pixy!blue/caddy-pixbooster@v0.1.0/module-withoutcgo.go:27:38: undefined: ImgFormat /root/go/pkg/mod/github.com/!pixy!blue/caddy-pixbooster@v0.1.0/module-withoutcgo.go:32:65: undefined: ImgFormat /root/go/pkg/mod/github.com/!pixy!blue/caddy-pixbooster@v0.1.0/module-withoutcgo.go:62:33: p.AvifConfig undefined (type Pixbooster has no field or method AvifConfig, but does have avifConfig) /root/go/pkg/mod/github.com/!pixy!blue/caddy-pixbooster@v0.1.0/module-withoutcgo.go:64:35: p.JxlConfig undefined (type *Pixbooster has no field or method JxlConfig, but does have jxlConfig)

taophp commented 2 months ago

Thanks for this. I missed that on my last commit, sorry. I'll fix it in a few minutes. But it is a compilation issue and seems unrelated with your initial one. In the meantime, could you please provide the log output with CGO enabled again ?

adammakowskidev commented 2 months ago

what exact logs do you need? can you give the configuration and where can I find them?

taophp commented 2 months ago

If you run xcaddy this way:

CGO_ENABLED=1 \
xcaddy run \
    --with github.com/dunglas/caddy-cbrotli \
    --with github.com/pberkel/caddy-storage-redis \
    --with github.com/PixyBlue/caddy-pixbooster \
    --config /path/to/your/Caddyfile

you'll get all the logs on the command line.

adammakowskidev commented 2 months ago

root@eu-de-fra-1-dynoble-net:~# systemctl status caddy ● caddy.service - Caddy Loaded: loaded (/lib/systemd/system/caddy.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2024-05-03 16:09:48 UTC; 19min ago Docs: https://caddyserver.com/docs/ Main PID: 6403 (caddy) Tasks: 10 (limit: 28690) Memory: 851.6M CPU: 35.713s CGroup: /system.slice/caddy.service └─6403 /usr/bin/caddy run --environ --config /etc/caddy/Caddyfile

May 03 16:29:02 eu-de-fra-1-dynoble-net caddy[6403]: {"level":"error","ts":1714753742.7054522,"logger":"http.handlers.pixbooster","msg":"Error converting image to format: .avif"} May 03 16:29:02 eu-de-fra-1-dynoble-net caddy[6403]: {"level":"error","ts":1714753742.7060752,"logger":"http.handlers.pixbooster","msg":"avif: mem write failed"} May 03 16:29:02 eu-de-fra-1-dynoble-net caddy[6403]: {"level":"error","ts":1714753742.7061913,"logger":"http.log.error","msg":"avif: mem write failed","request":{"remote_ip":"91.94.89.12","remote_port":"24956","client_ip":"91.94.89.12","proto":"HTTP/2.0">May 03 16:29:03 eu-de-fra-1-dynoble-net caddy[6403]: {"level":"error","ts":1714753743.0557148,"logger":"http.handlers.pixbooster","msg":"Error converting image to format: .avif"} May 03 16:29:03 eu-de-fra-1-dynoble-net caddy[6403]: {"level":"error","ts":1714753743.055763,"logger":"http.handlers.pixbooster","msg":"avif: encode failed"} May 03 16:29:03 eu-de-fra-1-dynoble-net caddy[6403]: {"level":"error","ts":1714753743.0558288,"logger":"http.log.error","msg":"avif: encode failed","request":{"remote_ip":"91.94.89.12","remote_port":"24956","client_ip":"91.94.89.12","proto":"HTTP/2.0","m>May 03 16:29:03 eu-de-fra-1-dynoble-net caddy[6403]: {"level":"error","ts":1714753743.2961764,"logger":"http.handlers.pixbooster","msg":"Error converting image to format: .avif"} May 03 16:29:03 eu-de-fra-1-dynoble-net caddy[6403]: {"level":"error","ts":1714753743.2962291,"logger":"http.handlers.pixbooster","msg":"avif: encode failed"} May 03 16:29:03 eu-de-fra-1-dynoble-net caddy[6403]: {"level":"error","ts":1714753743.2962947,"logger":"http.log.error","msg":"avif: encode failed","request":{"remote_ip":"91.94.89.12","remote_port":"24956","client_ip":"91.94.89.12","proto":"HTTP/2.0","m>May 03 16:29:03 eu-de-fra-1-dynoble-net caddy[6403]: {"level":"error","ts":1714753743.366159,"logger":"http.log.error","msg":"open e22f2499211c68793e13c9a248316cf8: permission denied","request":{"remote_ip":"91.94.89.12","remote_port":"24956","client_ip">

adammakowskidev commented 2 months ago

May 03 16:34:37 eu-de-fra-1-dynoble-net caddy[7320]: {"level":"debug","ts":1714754077.5467873,"logger":"http.handlers.file_server","msg":"opening file","filename":"usr/share/caddy/assets/img/blog-header.jpg"} May 03 16:34:37 eu-de-fra-1-dynoble-net caddy[7320]: {"level":"debug","ts":1714754077.5547514,"logger":"http.handlers.pixbooster","msg":"Pixbooster start"} May 03 16:34:37 eu-de-fra-1-dynoble-net caddy[7320]: {"level":"debug","ts":1714754077.5548437,"logger":"http.handlers.file_server","msg":"sanitized path join","site_root":"./usr/share/caddy","request_path":"/robots.txt","result":"usr/share/caddy/robots.t>May 03 16:34:37 eu-de-fra-1-dynoble-net caddy[7320]: {"level":"debug","ts":1714754077.5548918,"logger":"http.log.error","msg":"{id=acyug0grs} fileserver.(*FileServer).notFound (staticfiles.go:629): HTTP 404","request":{"remote_ip":"91.94.89.12","remote_p>May 03 16:34:37 eu-de-fra-1-dynoble-net caddy[7320]: {"level":"debug","ts":1714754077.7866795,"logger":"http.handlers.pixbooster","msg":"Pixbooster start"} May 03 16:34:37 eu-de-fra-1-dynoble-net caddy[7320]: {"level":"debug","ts":1714754077.786716,"logger":"http.handlers.file_server","msg":"sanitized path join","site_root":"./usr/share/caddy","request_path":"/assets/img/favicon.png","result":"usr/share/cad>May 03 16:34:37 eu-de-fra-1-dynoble-net caddy[7320]: {"level":"debug","ts":1714754077.7867556,"logger":"http.handlers.file_server","msg":"precompressed file not accessible","filename":"usr/share/caddy/assets/img/favicon.png.zst","error":"stat usr/share/c>May 03 16:34:37 eu-de-fra-1-dynoble-net caddy[7320]: {"level":"debug","ts":1714754077.786765,"logger":"http.handlers.file_server","msg":"precompressed file not accessible","filename":"usr/share/caddy/assets/img/favicon.png.br","error":"stat usr/share/cad>May 03 16:34:37 eu-de-fra-1-dynoble-net caddy[7320]: {"level":"debug","ts":1714754077.786771,"logger":"http.handlers.file_server","msg":"precompressed file not accessible","filename":"usr/share/caddy/assets/img/favicon.png.gz","error":"stat usr/share/cad>May 03 16:34:37 eu-de-fra-1-dynoble-net caddy[7320]: {"level":"debug","ts":1714754077.7867737,"logger":"http.handlers.file_server","msg":"opening file","filename":"usr/share/caddy/assets/img/favicon.png"}

taophp commented 2 months ago

Strange. Your first log indicate memory usage when converting picture to avif. In the second one, I can't see anything related to Pixbooster, except the start. Could you try to add noavif key in the route section and post the log again? It will disable Avif output, but you should still get Webp and Jxl. As Jxl is rarely supported today, I expect the Webp output to work: if yes, the issue should be only avif related ; if no, I suppose it should be a memory usage issue.

adammakowskidev commented 2 months ago

Hmm looks like it was a problem with the site.... I built a quick index.html on loading just one image and now everything works. I use this template - https://bootstrapmade.com/nova-bootstrap-business-template/

But RAM usage for 1 image is terrible hight, almost 400mb

taophp commented 2 months ago

The template works well on my side... But I have a idea. Try to install libavif and `libaom3:

apt install libavif-bin libaom3 libaom-dev aom-tools libavif-dev libavif16

Not sure that the four last packages are required, I added them just in case. The Go avif package tell us:

Based on libavif and aom compiled to WASM and used with wazero runtime (CGo-free). The library will first try to use a dynamic/shared library (if installed) via purego and will fall back to WASM.

I expect the WASM implementation to be much more memory hungry than the native one. Please, let me know.

adammakowskidev commented 2 months ago

It didn't change anything after installing the software, and when I send more traffic to this image the server crashes. And it has 4CPU and 24GB of ram so it is not small

taophp commented 1 month ago

Please, try to desactive avif output adding the noavif key to the route section like this:

route {
   pixbooster noavif
}

So, no avif file will be proposed. Your browser should receive webp files (except if you use one of the latest Safari, in this case, JXL will be send). Then we should know if the issue is linked to avif or more general.