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

"Error:SVG data parsing failed cause unknown token" when running on standalone server #489

Closed
Tonyce opened this issue Sep 3, 2024 · 11 comments

Comments

@Tonyce
Copy link

Tonyce commented Sep 3, 2024

Error: failed to pipe responseat pipeToNodeResponse(/app/node_modules/.pnpm/[email protected] reac
at async sendResponse(/app/node modules/.pnpm/[email protected] reac
at async doRender (/app/node modules/.pnpm/[email protected] react-dor
at async cacheEntry.responseCache.get.routeKind(/app/node_modu
at async NextNodeServer.renderToResponseWithComponentsImpl (/ap
at async NextNodeServer.renderPageComponent (/app/node_modules/
at async NextNodeServer.renderToResponseImpl (/app/node_modules.
at async NextNodeServer.pipeImpl (/app/node_ modules/.pnpm/next@
at async NextNodeServer.handleCatchallRenderRequest (/app/node.
at async NextNodeServer.handleRequestImpl (/app/node modules/.p!Icause]: Error:SVG data parsing failed cause unknown token at 1:at imports.wbg.wbg new 15d3966e9981a196(file:///app/node mo
at wasm://wasm/005420d6:wasm-function[515]:0x112c4cat wasm://wasm/005420d6:wasm-function[30]:0x3ffde

@stephancill
Copy link
Contributor

Hi, please share a reproducible example or the frame route that you are seeing this error on

@Tonyce
Copy link
Author

Tonyce commented Sep 4, 2024

https://github.com/Tonyce/frames-debug . Keep requesting /frames/image and you will get this error

@stephancill
Copy link
Contributor

thanks for providing the repo. i'm unable to run it - can't request /frames/images directly and /frames requires some external API access

@davidfurlong davidfurlong added the Frames.js label Sep 9, 2024 — with Linear
@stephancill stephancill changed the title image fail "Error:SVG data parsing failed cause unknown token" when running on VPS Sep 14, 2024
@stephancill
Copy link
Contributor

Turns out @vercel/og has a memory leak that doesn't manifest itself in serverless contexts. The workaround is to patch the @vercel/og package in your project - see the necessary changes in this comment thx/resvg-js#216 (comment)

Here is the an exact diff for @vercel+og+0.6.2

diff --git a/node_modules/@vercel/og/dist/index.node.js b/node_modules/@vercel/og/dist/index.node.js
index c92983c..a516f4f 100644
--- a/node_modules/@vercel/og/dist/index.node.js
+++ b/node_modules/@vercel/og/dist/index.node.js
@@ -18786,7 +18786,11 @@ async function render(satori2, resvg, opts, defaultFonts, element) {
       value: options.width
     }
   });
-  return resvgJS.render().asPng();
+  const pngData = resvgJS.render();
+  const pngBuffer = pngData.asPng();
+  pngData.free();
+  resvgJS.free();
+  return pngBuffer;
 }
 
 // src/figma/index.tsx

@stephancill stephancill changed the title "Error:SVG data parsing failed cause unknown token" when running on VPS "Error:SVG data parsing failed cause unknown token" when running on server Sep 14, 2024
@stephancill stephancill changed the title "Error:SVG data parsing failed cause unknown token" when running on server "Error:SVG data parsing failed cause unknown token" when running on standalone server Sep 14, 2024
@dalechyn
Copy link

Seems to be still ongoing in upstream, @ggomaeng tried to fix it in frog as well: wevm/hono-og#37 (comment)
upstream ref: vercel/next.js#61047

@stephancill
Copy link
Contributor

stephancill commented Sep 16, 2024

Update: it seems like it did not fix the problem after all. Still getting this error, just less frequently

@Tonyce
Copy link
Author

Tonyce commented Sep 19, 2024

update "@vercel/og" to "^0.6.3"

@Tonyce
Copy link
Author

Tonyce commented Sep 19, 2024

it's a OOM bug because @vercel/og, @vercel/og has release new version

@stephancill
Copy link
Contributor

@Tonyce did the problem go away for you in 0.6.3?

@Tonyce
Copy link
Author

Tonyce commented Sep 19, 2024

yes, I ran a stress test and everything seemed fine.

@stephancill
Copy link
Contributor

Should be fixed in [email protected]

dalechyn added a commit to dalechyn/hono-og that referenced this issue Sep 20, 2024
Fixes an issue with the memory leak.
Original upstream issue: vercel/next.js#70091
frames.js related issue: framesjs/frames.js#489
tmm pushed a commit to wevm/hono-og that referenced this issue Sep 20, 2024
* chore: bump @vercel/og

Fixes an issue with the memory leak.
Original upstream issue: vercel/next.js#70091
frames.js related issue: framesjs/frames.js#489

* chore: changesets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants