sveltejs / kit

web development, streamlined
https://kit.svelte.dev
MIT License
18.52k stars 1.91k forks source link

adapter-node upgrade lead to Memory Leak on SSR #12259

Open paras-taneja opened 4 months ago

paras-taneja commented 4 months ago

Describe the bug

We are observing memory leak in our code after upgrading to svelte kit 2. On further investigation found out the leak is coming from the fetch function (part of event object and not global fetch) used in load function of page.ts. To validate the fact we used global fetch and saw no memory leak.

Reproduction

1) Create new svelte-kit project using this command => npm create svelte@latest my-app 2) call an api in load function in one of the page.ts using load fetch and not global fetch

Logs

N.A

System Info

System:
    OS: macOS 12.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 81.33 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 18.18.0 - ~/.nvm/versions/node/v18.18.0/bin/node
    npm: 9.8.1 - ~/.nvm/versions/node/v18.18.0/bin/npm
    pnpm: 7.30.0 - ~/Library/pnpm/pnpm
  Browsers:
    Chrome: 125.0.6422.76
    Safari: 15.2
  npmPackages:
    @bulatdashiev/svelte-slider: 1.0.3 => 1.0.3 
    @lottiefiles/svelte-lottie-player: ^0.3.1 => 0.3.1 
    @playwright/test: 1.28.1 => 1.28.1 
    @sveltejs/adapter-node: 2.1.2 => 2.1.2 
    @sveltejs/kit: 2.5.0 => 2.5.0 
    @sveltejs/vite-plugin-svelte: 3.0.2 => 3.0.2 
    @typescript-eslint/eslint-plugin: 5.61.0 => 5.61.0 
    @typescript-eslint/parser: 5.61.0 => 5.61.0 
    @vite-pwa/sveltekit: 0.2.7 => 0.2.7 
    autoprefixer: 10.4.14 => 10.4.14 
    cache-manager: ^5.4.0 => 5.4.0 
    cookie-es: 0.5.0 => 0.5.0 
    daisyui: 2.51.4 => 2.51.4 
    date-fns: 2.30.0 => 2.30.0 
    eslint: 8.44.0 => 8.44.0 
    eslint-config-prettier: 8.8.0 => 8.8.0 
    eslint-plugin-import: ^2.29.1 => 2.29.1 
    eslint-plugin-simple-import-sort: ^12.0.0 => 12.1.0 
    eslint-plugin-svelte3: 4.0.0 => 4.0.0 
    fflate: 0.7.4 => 0.7.4 
    fluent-svelte: ^1.6.0 => 1.6.0 
    hls.js: ^1.5.7 => 1.5.7 
    husky: 8.0.3 => 8.0.3 
    jsonwebtoken: 9.0.0 => 9.0.0 
    kolorist: ^1.8.0 => 1.8.0 
    lodash.merge: 4.6.2 => 4.6.2 
    ohash: ^1.1.3 => 1.1.3 
    postcss: 8.4.35 => 8.4.35 
    prettier: 2.8.8 => 2.8.8 
    prettier-plugin-svelte: 2.10.0 => 2.10.0 
    prettier-plugin-tailwindcss: 0.3.0 => 0.3.0 
    rollup-plugin-visualizer: 5.9.2 => 5.9.2 
    svelte: 4.2.1 => 4.2.1 
    svelte-check: 3.5.2 => 3.5.2 
    tailwindcss: 3.3.3 => 3.3.3 
    tslib: 2.6.0 => 2.6.0 
    typescript: 5.2.2 => 5.2.2 
    ua-parser-js: ^1.0.35 => 1.0.35 
    vite: 5.0.12 => 5.0.12 
    vite-plugin-pwa: 0.16.4 => 0.16.4 
    vitest: 1.2.2 => 1.2.2

Severity

annoyance

Additional Information

No response

paras-taneja commented 4 months ago

On Further investigation found out the "@sveltejs/adapter-node" package had the leak, downgraded the version to "1.2.4"

dummdidumm commented 4 months ago

Which version was the adapter node package prior to downgrading? Did you try updating to the latest LTS version of Node.js (20)? (If that leak stems from undici which comes bundled with node)

paras-taneja commented 4 months ago

@sveltejs/adapter-node: 2.1.2 was the version before downgrading. Current Node Version is 18.3 will try with above mentioned version and check on the leak