sveltejs / language-tools

The Svelte Language Server, and official extensions which use it
MIT License
1.22k stars 196 forks source link

Extension keep crashing: MarkCompactCollector #2510

Open Extarys opened 2 hours ago

Extarys commented 2 hours ago

Describe the bug

Every time I try to run "Format document", after 10-20 seconds I get an error in Output > Svelte and nothing happens


<--- Last few GCs --->

[1079:0x63000364000]    76965 ms: Scavenge 3914.9 (4084.8) -> 3912.1 (4087.0) MB, pooled: 0 MB, 4.13 / 0.00 ms  (average mu = 0.814, current mu = 0.575) allocation failure; 
[1079:0x63000364000]    76986 ms: Scavenge 3917.1 (4087.0) -> 3914.2 (4089.5) MB, pooled: 0 MB, 7.72 / 0.00 ms  (average mu = 0.814, current mu = 0.575) allocation failure; 

<--- JS stacktrace --->

FATAL ERROR: MarkCompactCollector: young object promotion failed Allocation failed - JavaScript heap out of memory
----- Native stack trace -----

[Error - 20:51:07] Server process exited with signal SIGABRT.
[Info  - 20:51:07] Connection to server got closed. Server will restart.
true
Initialize language server at  file:///srv/repo
Initialize new ts service at  /srv/repo/apps/ui/tsconfig.json
Trying to load configs for /srv/repo/apps/ui
Loaded config at  /srv/repo/apps/ui/svelte.config.js
SnapshotManager File Statistics:
Project files: 295
Svelte files: 212
From node_modules: 0
Total: 295
No svelte.config.js found. Using https://github.com/sveltejs/svelte-preprocess as fallback
No svelte.config.js found. Using https://github.com/sveltejs/svelte-preprocess as fallback

(I have a lot of those)

Output > Extension Host

2024-09-20 21:15:10.088 [error] Error: Pending response rejected since connection got disposed
    at Object.dispose (/home/user/.var/app/com.vscodium.codium/data/codium/extensions/svelte.svelte-vscode-109.0.1-universal/node_modules/vscode-jsonrpc/lib/common/connection.js:1167:27)
    at Object.dispose (/home/user/.var/app/com.vscodium.codium/data/codium/extensions/svelte.svelte-vscode-109.0.1-universal/node_modules/vscode-languageclient/lib/common/client.js:1586:35)
    at LanguageClient.handleConnectionClosed (/home/user/.var/app/com.vscodium.codium/data/codium/extensions/svelte.svelte-vscode-109.0.1-universal/node_modules/vscode-languageclient/lib/common/client.js:1155:34)
    at LanguageClient.handleConnectionClosed (/home/user/.var/app/com.vscodium.codium/data/codium/extensions/svelte.svelte-vscode-109.0.1-universal/node_modules/vscode-languageclient/lib/node/main.js:180:22)
    at closeHandler (/home/user/.var/app/com.vscodium.codium/data/codium/extensions/svelte.svelte-vscode-109.0.1-universal/node_modules/vscode-languageclient/lib/common/client.js:1142:18)
    at CallbackList.invoke (/home/user/.var/app/com.vscodium.codium/data/codium/extensions/svelte.svelte-vscode-109.0.1-universal/node_modules/vscode-jsonrpc/lib/common/events.js:55:39)
    at Emitter.fire (/home/user/.var/app/com.vscodium.codium/data/codium/extensions/svelte.svelte-vscode-109.0.1-universal/node_modules/vscode-jsonrpc/lib/common/events.js:117:36)
    at closeHandler (/home/user/.var/app/com.vscodium.codium/data/codium/extensions/svelte.svelte-vscode-109.0.1-universal/node_modules/vscode-jsonrpc/lib/common/connection.js:314:26)
    at CallbackList.invoke (/home/user/.var/app/com.vscodium.codium/data/codium/extensions/svelte.svelte-vscode-109.0.1-universal/node_modules/vscode-jsonrpc/lib/common/events.js:55:39)
    at Emitter.fire (/home/user/.var/app/com.vscodium.codium/data/codium/extensions/svelte.svelte-vscode-109.0.1-universal/node_modules/vscode-jsonrpc/lib/common/events.js:117:36)
    at IPCMessageReader.fireClose (/home/user/.var/app/com.vscodium.codium/data/codium/extensions/svelte.svelte-vscode-109.0.1-universal/node_modules/vscode-jsonrpc/lib/common/messageReader.js:41:27)
    at ChildProcess.<anonymous> (/home/user/.var/app/com.vscodium.codium/data/codium/extensions/svelte.svelte-vscode-109.0.1-universal/node_modules/vscode-jsonrpc/lib/node/main.js:37:45)
    at ChildProcess.emit (node:events:531:35)
    at maybeClose (node:internal/child_process:1105:16)
    at Socket.<anonymous> (node:internal/child_process:457:11)
    at Socket.emit (node:events:519:28)
    at Pipe.<anonymous> (node:net:338:12)

Reproduction

I have this issue with VSCodium rpm and VSCodium flatpak. No idea how to reproduce.

Monorepo with a ui folder, containing svelte.config.js (Sveltekit, vite).

Formatting work on a 25 LOC file, but another component with 95 LOC make it crash every single time. I tried multiple page and they mostly all make the language server crash.

I don't really know what you need, please let me know. It was working fine 2 days ago, I didn't update any npm package, but I have no idea if vscode did update extensions in the background, so I erased all tmp and config files and tested with flatpak too, issue still persist.

Expected behaviour

The extension shouldn't crash; The document should get formatted

System Info

Which package is the issue about?

Svelte for VS Code extension, svelte-language-server

Additional Information, eg. Screenshots

Old similar issue: https://github.com/jamesbirtles/svelte-vscode/issues/26

jasonlyu123 commented 2 hours ago

We'll definitely need a reproduction to help you. Formatting usually only works with the current file so it shouldn't use that much memory that would crash the process. I suspect it might be some infinite loop/recursive call. Can you try copying the problematic files or the prettier config file to an empty svelte-kit project to see if you can reproduce it? If you still can't find a reproduction, please at least provide the dependencies and devDependencies in your package.json, the tsconfig.json/jsconfig.json and the prettier config file.

Extarys commented 2 hours ago

I'll get started on some of those right away:

package.json

{
    "devDependencies": {
        "@repo/api-hono": "workspace:*",
        "@repo/dto": "workspace:*",
        "@repo/edgedb": "workspace:*",
        "@fortawesome/fontawesome-pro": "^6.6.0",
        "@fortawesome/free-brands-svg-icons": "^6.6.0",
        "@fortawesome/pro-duotone-svg-icons": "^6.6.0",
        "@fortawesome/pro-light-svg-icons": "^6.6.0",
        "@fortawesome/pro-regular-svg-icons": "^6.6.0",
        "@fortawesome/pro-solid-svg-icons": "^6.6.0",
        "@fortawesome/pro-thin-svg-icons": "^6.6.0",
        "@fortawesome/sharp-duotone-solid-svg-icons": "^6.6.0",
        "@fortawesome/sharp-light-svg-icons": "^6.6.0",
        "@fortawesome/sharp-regular-svg-icons": "^6.6.0",
        "@fortawesome/sharp-solid-svg-icons": "^6.6.0",
        "@fortawesome/sharp-thin-svg-icons": "^6.6.0",
        "@fortawesome/svelte-fontawesome": "^0.2.2",
        "@playwright/test": "^1.28.1",
        "@sveltejs/adapter-auto": "^3.0.0",
        "@sveltejs/kit": "^2.5.26",
        "@sveltejs/vite-plugin-svelte": "^4.0.0-next.6",
        "@types/eslint": "^9.6.0",
        "eslint": "^9.0.0",
        "eslint-config-prettier": "^9.1.0",
        "eslint-plugin-svelte": "^2.36.0",
        "globals": "^15.0.0",
        "prettier": "^3.1.1",
        "prettier-plugin-svelte": "^3.1.2",
        "svelte": "^5.0.0-next.245",
        "svelte-check": "^4.0.0",
        "typescript": "^5.0.0",
        "typescript-eslint": "^8.0.0",
        "vite": "^5.0.3",
        "vitest": "^2.0.0",
        "tailwindcss": "^3.4.4",
        "postcss": "^8.4.38",
        "autoprefixer": "^10.4.19",
        "@tailwindcss/typography": "^0.5.15",
        "prettier-plugin-tailwindcss": "^0.6.4"
    },
    "type": "module",
    "dependencies": {
        "@cartamd/plugin-attachment": "^4.0.2",
        "@cartamd/plugin-code": "^4.0.6",
        "@cartamd/plugin-component": "^1.0.2",
        "@cartamd/plugin-emoji": "^4.1.3",
        "@cartamd/plugin-slash": "^4.0.2",
        "@internationalized/date": "^3.5.5",
        "@paralleldrive/cuid2": "^2.2.2",
        "@tiptap/core": "^2.7.2",
        "@tiptap/extension-dropcursor": "^2.7.2",
        "@tiptap/extension-link": "^2.7.2",
        "@tiptap/extension-underline": "^2.7.2",
        "@tiptap/pm": "^2.7.2",
        "@tiptap/starter-kit": "^2.7.2",
        "bits-ui": "^0.21.13",
        "carta-md": "^4.4.5",
        "clsx": "^2.1.1",
        "cmdk-sv": "^0.0.18",
        "formsnap": "^1.0.1",
        "isomorphic-dompurify": "^2.15.0",
        "lucide-svelte": "^0.439.0",
        "mode-watcher": "^0.4.1",
        "paneforge": "^0.0.5",
        "svelte-fa": "^4.0.2",
        "svelte-persisted-store": "^0.11.0",
        "svelte-tiptap": "^1.1.3",
        "sveltekit-superforms": "^2.17.0",
        "tailwind-merge": "^2.5.2",
        "tailwind-variants": "^0.2.1",
        "zod": "^3.23.8"
    }
}

tsconfig:

{
    "extends": "./.svelte-kit/tsconfig.json",
    "compilerOptions": {
        "allowJs": true,
        "checkJs": true,
        "esModuleInterop": true,
        "forceConsistentCasingInFileNames": true,
        "resolveJsonModule": true,
        "skipLibCheck": true,
        "sourceMap": true,
        "strict": true,
        "moduleResolution": "bundler"
    }
    // Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
    // except $lib which is handled by https://kit.svelte.dev/docs/configuration#files
    //
    // If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
    // from the referenced tsconfig.json - TypeScript does not merge them in
}

Prettier

{
    "useTabs": true,
    "singleQuote": true,
    "trailingComma": "none",
    "printWidth": 100,
    "plugins": ["prettier-plugin-svelte", "prettier-plugin-tailwindcss"],
    "overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
}

Exemple of file that make the extension crash:

<script lang="ts">
    import { zod } from 'sveltekit-superforms/adapters';
    import { goto } from '$app/navigation';
    import SuperDebug, {
        type SuperValidated,
        type Infer,
        superForm,
        setMessage,
        defaults
    } from 'sveltekit-superforms';

    import { loginFormSchema } from '@repo/dto';

    // UI elements
    import * as Card from '$lib/components/ui/card/index.js';
    import * as Form from '$lib/components/ui/form';
    import { Input } from '$lib/components/ui/input';
    import { Button } from '$lib/components/ui/button';

    const form = superForm(defaults(zod(loginFormSchema)), {
        SPA: true,
        resetForm: false,
        validators: zod(loginFormSchema),
        dataType: 'json',
        delayMs: 500,
        timeoutMs: 4000,
        onUpdate: async ({ form }) => {

        }
    });

    const { form: formData, enhance, errors, submitting, delayed, timeout, validate, message } = form;
</script>

<div class="grid place-items-center h-screen shadow">
            <form use:enhance>
        <Card.Root class="flex flex-col w-96 h-96 rounded-sm border shadow-lg">
            <Card.Header>Title</Card.Header>
            <Card.Content>
                <Form.Field {form} name="username">
                    <Form.Control let:attrs>
                        <Form.Label>Username</Form.Label>
                        <Input {...attrs} bind:value={$formData.identifier} />
                    </Form.Control>
                    <Form.FieldErrors />
                </Form.Field>
                <Form.Field {form} name="username">
                    <Form.Control let:attrs>
                        <Form.Label>Password</Form.Label>
                        <Input {...attrs} bind:value={$formData.clearPassword} type="password" />
                    </Form.Control>
                    <Form.FieldErrors />
                </Form.Field>
            </Card.Content>
            <Card.Footer class="flex flex-row">
                <Button type="submit" class="ml-auto">Login</Button>
            </Card.Footer>
        </Card.Root>
    </form>
</div>

<style lang="postcss">
</style>

I'll try to make a reproduction tomorrow ;) But in the meantime maybe there is a hint somewhere in there.

Is there a way to make the extension logs more verbose to help pinpoint the issue?