yuzutech / kroki

Creates diagrams from textual descriptions!
https://kroki.io
MIT License
2.97k stars 224 forks source link

Error with Vega Lite in 0.26.0 #1806

Closed pando85 closed 1 week ago

pando85 commented 2 weeks ago

Hello,

I updated to 0.26 and now my requests are failing:

Error 400: Error: CanvasRenderer is missing a valid canvas or context
    at Object.error (/snapshot/app/node_modules/vega-util/build/vega-util.js:36:11)
    at CanvasRenderer.resize (/snapshot/app/node_modules/vega-scenegraph/build/vega-scenegraph.js:4871:28)
    at CanvasRenderer.initialize (/snapshot/app/node_modules/vega-scenegraph/build/vega-scenegraph.js:4465:19)
    at CanvasRenderer.initialize (/snapshot/app/node_modules/vega-scenegraph/build/vega-scenegraph.js:4861:20)
    at initializeRenderer (/snapshot/app/node_modules/vega-view/build/vega-view.js:657:14)
    at renderHeadless (/snapshot/app/node_modules/vega-view/build/vega-view.js:771:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async View.renderToCanvas [as toCanvas] (/snapshot/app/node_modules/vega-view/build/vega-view.js:803:15)
    at async convert (/snapshot/app/src/convert.js:51:20)
    at async convert (/snapshot/app/src/index.js:19:20)
pando85 commented 2 weeks ago

I guess that it has to be related with the canvas upgrade to ^3.0.0-rc2. Vega-lite is still on 2.11.2

ggrossetie commented 2 weeks ago

I cannot reproduce this issue on https://kroki.io/. Could you please provide a reproduction case?

pando85 commented 2 weeks ago

You are right. I cannot reproduce now with an small test and 0.26.0 docker image or https://kroki.io/

I will close this, I don't know what I saw this morning. Sorry for bothering you.

pando85 commented 2 weeks ago

I was able to reproduce it running kroki like this:

docker run --rm -p 8000:8000 -u 65534 yuzutech/kroki:0.26.0

On 0.25.0 it was working perfectly. Also, I would like to avoid running it as root.

ggrossetie commented 1 week ago

I cannot reproduce on my host:

$ docker run --rm -p 8000:8000 yuzutech/kroki:0.26.0
{"timestamp":"1731527551379","level":"INFO","thread":"vert.x-eventloop-thread-0","logger":"io.vertx.core.impl.launcher.commands.VertxIsolatedDeployer","message":"Succeeded in deploying verticle","context":"default"}
{"timestamp":"1731527555195","level":"INFO","thread":"vert.x-eventloop-thread-1","mdc":{"path":"/vegalite/svg","method":"POST","service_name":"vegalite","action":"request_received","bytes_read":"2793","user_agent":"HTTPie/3.2.2"},"logger":"io.kroki.server.service.DiagramHandler","message":"Request received POST /vegalite/svg","context":"default"}
{"timestamp":"1731527555500","level":"INFO","thread":"vert.x-eventloop-thread-1","mdc":{"path":"/vegalite/svg","took":"303","method":"POST","service_name":"vegalite","action":"convert","file_format":"svg","user_agent":"HTTPie/3.2.2"},"logger":"io.kroki.server.service.DiagramHandler","message":"Convert took 303ms","context":"default"}
$ cat diag.vlite | http :8000/vegalite/svg Content-Type:text-plain
HTTP/1.1 200 OK
cache-control: public, max-age=432000
content-length: 23895
content-type: image/svg+xml
date: Wed, 13 Nov 2024 19:52:35 GMT
etag: 5.21.0dlaIpK0LPBp2BGm3OICRyW00
expires: Mon, 18 Nov 2024 19:52:35 GMT
last-modified: Sun, 10 Nov 2024 19:58:41 GMT

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" class="marks" width="402" height="192" viewBox="0 0 402 192">
  <rect width="402" height="192" fill="white"/>
(...)
</svg>
$ cat /etc/*release*
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=24.04
DISTRIB_CODENAME=noble
DISTRIB_DESCRIPTION="Ubuntu 24.04.1 LTS"
PRETTY_NAME="Ubuntu 24.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.1 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo
$ docker -v
Docker version 27.3.1, build ce12230

Also, I would like to avoid running it as root.

You don't need to run it as root.

pando85 commented 1 week ago

Hey, see the -u option in my command to reproduce it.

You are running it as root.

In 0.25.0 it worked with that configuration.

ggrossetie commented 1 week ago

I don't think that's true, since the container is using the user kroki:

https://github.com/yuzutech/kroki/blob/65e9231eb36405971cb47c141cb7f169a1f2cc2e/server/ops/docker/jdk17-noble/Dockerfile#L275

Is there a reason to run it with -u 65534 (nobody)? Is it working if you remove the -u option? I'm not really sure why/how it worked with 0.25.0.

Having said that, we should probably revert Canvas version to 2.11.2. However, I don't think if it will fix your issue since I don't really understand the relationship between the Canvas error and running the container with the nobody user. It does not make much sense 🤔

pando85 commented 1 week ago

Yep, it's really weird. Now I've checked the Dockerfile, and you're totally right. In 0.26.0, the Kroki user is 1001. I will run it with that user, which seems to work.

The build of vega doesn't change so much between 0.25.0 and 0.26.0. So, I don't understand the canvas error.

Anyway, thanks for your guidance. I will close it.

pando85 commented 1 week ago

Just for the record: if I ran with readOnlyRootFilesystem: true and user ID 1001, it still fails. So, vega is writing at some path in the container.

ggrossetie commented 1 week ago

Just for the record: if I ran with readOnlyRootFilesystem: true and user ID 1001, it still fails. So, vega is writing at some path in the container.

Ah I see... I will try to investigate a bit further. Thanks!