[lsp-server] 🐞 Heap out of memory
Is there an existing issue for this?
- [x] I have searched the existing issues
Current Behavior
In our big project, we are constantly seeing crashes like this:
<--- Last few GCs --->
[3450436:0x18d8000e8000] 6166 ms: Mark-Compact (reduce) 2853.2 (2882.3) -> 2853.2 (2875.3) MB, pooled: 0 MB, 50.26 / 0.00 ms (average mu = 0.615, current mu = 0.260) last resort; GC in old space requested
[3450436:0x18d8000e8000] 6220 ms: Mark-Compact (reduce) 2853.2 (2875.3) -> 2853.2 (2875.3) MB, pooled: 0 MB, 53.84 / 0.00 ms (average mu = 0.414, current mu = 0.001) last resort; GC in old space requested
<--- JS stacktrace --->
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
----- Native stack trace -----
[Error - 09:51:48] The vscode-graphql server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.
[Info - 09:51:48] The graphql server has stopped running
Any ideas / solutions for this?
Expected Behavior
Should not crash or at least show a graceful error message
Steps To Reproduce
Run VSCode with a big project
Environment
- LSP Server Version: 0.13.0 (2025-02-19, 18:23:00)
- OS: Ubuntu 24.04
- LSP Client: VSCode v1.97.2
Anything else?
Happens on a similar system with the same projects for a colleague as well.
hello @MeKo-Christian - there is a refactor underway that should reduce the memory usage, as some drift has caused a bit of duplication in cacheing. can you share your graphql config file, with any necessary redactions? i may be able to help you find ways to optimize it for the time being
Sorry for the late response, but increasing the heap memory with export NODE_OPTIONS="--max-old-space-size=4096" solved it back then. Now it appeared again, and we want this to get fixed on the root.
This said, our .graphqlrc.yml is plain simple:
schema: "./src/gql/schema.graphql"
The codegen.ts not, but mostly due to the need for getting the token:
import { CodegenConfig } from "@graphql-codegen/cli";
import { execSync } from "child_process";
import dotenv from "dotenv";
// eslint-disable-next-line import/no-named-as-default-member
dotenv.config();
// eslint-disable-next-line import/no-named-as-default-member
dotenv.config({ path: ".env.development", override: true });
function getAccessTokenSync(): string {
try {
const output = execSync("node scripts/getAccessToken.js", {
encoding: "utf-8",
});
return output.trim();
} catch (error) {
console.error("Failed to retrieve access token", error);
process.exit(1);
}
}
const accessToken = getAccessTokenSync();
let introspectionServer = process.env.VITE_GRAPHQL_API_URL || "local";
switch (introspectionServer) {
case "1":
introspectionServer =
"https://redacted.dev/integration_1/v1/graphql";
break;
case "2":
introspectionServer =
"https://redacted.dev/integration_2/v1/graphql";
break;
case "3":
introspectionServer =
"https://redacted.dev/integration_3/v1/graphql";
break;
case "staging":
introspectionServer = "https://redacted.dev/staging/v1/graphql";
break;
case "local":
introspectionServer = "http://localhost:8080/v1/graphql";
break;
}
const config: CodegenConfig = {
overwrite: true,
schema: {
[introspectionServer]: {
headers: {
Authorization: `Bearer ${accessToken}`,
},
},
},
documents: ["./src/api/**/*.ts", "./src/queryHooks/**/*.ts"],
generates: {
"./src/__generated__/apiTypes.ts": {
plugins: [
"typescript",
"typescript-operations",
"typescript-react-apollo",
],
config: {
avoidOptionals: {
inputValue: false,
field: true,
},
preResolveTypes: true,
namingConvention: "keep",
},
},
"src/gql/": {
preset: "client",
plugins: [],
config: {
namingConvention: "keep",
},
},
"./src/gql/schema.graphql": {
plugins: ["schema-ast"],
},
},
};
export default config;
However, the schema.graphql is about 2.2MB big. Maybe that's an issue?