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

[Bug]: Language Server shuts down when using a Ballerina project with large files #41862

Closed
Nuvindu opened this issue Dec 11, 2023 · 11 comments
Closed
Assignees
Labels
Fix/Crash All issues caused by NPE, CCE, etc Reason/Other None of the other reasons. Team/Observability Observability in general, Metrics, Tracing & Logging Type/Bug

Comments

@Nuvindu
Copy link
Contributor

Nuvindu commented Dec 11, 2023

Description

When working with a Ballerina project that includes large files, particularly generated from an OpenAPI specification, the Ballerina Language Server unexpectedly shuts down, resulting in a "Stopping server timed out" error. This issue appears to be triggered when attempting to work with the generated Ballerina files.

Output log:

[Error - 16:53:27] Stopping server failed
Error: Stopping the server timed out
    at /Users/nuvindu/.vscode/extensions/wso2.ballerina-4.5.6/dist/extension.js:2:997853

Steps to Reproduce

  1. Download the OpenAPI spec from here.
  2. Create a new Ballerina project.
  3. Run the bal openapi -i esignature.rest.swagger-v2.1.json --mode client --client-methods resource command to generate client.bal, types.bal, and utils.bal files.
  4. Use the generated Ballerina project in the VS Code environment.
@ballerina-bot ballerina-bot added the needTriage The issue has to be inspected and labeled manually label Dec 11, 2023
@LakshanWeerasinghe LakshanWeerasinghe added Team/LanguageServer Language Server Implementation related issues. #Compiler Fix/Crash All issues caused by NPE, CCE, etc and removed needTriage The issue has to be inspected and labeled manually labels Dec 11, 2023
@nipunayf nipunayf assigned nipunayf and unassigned nipunayf Dec 12, 2023
@nipunayf
Copy link
Contributor

nipunayf commented Dec 13, 2023

The error is due to an out-of-memory issue occurring during the project build. The following error message is generated when we execute the bal build command.

[2023-12-13 13:22:19,567] SEVERE {b7a.log.crash} - Java heap space 
java.lang.OutOfMemoryError: Java heap space
        at java.base/java.util.Arrays.copyOf(Arrays.java:3537)
        at java.base/java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:241)
        at java.base/java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:685)
        at java.base/java.lang.StringBuffer.append(StringBuffer.java:393)
        at java.base/java.io.StringWriter.write(StringWriter.java:122)
        at com.google.gson.stream.JsonWriter.string(JsonWriter.java:642)
        at com.google.gson.stream.JsonWriter.writeDeferredName(JsonWriter.java:402)
        at com.google.gson.stream.JsonWriter.value(JsonWriter.java:417)
        at com.google.gson.internal.bind.TypeAdapters$28.write(TypeAdapters.java:832)
        at com.google.gson.internal.bind.TypeAdapters$28.write(TypeAdapters.java:846)
        at com.google.gson.internal.bind.TypeAdapters$28.write(TypeAdapters.java:838)
        at com.google.gson.internal.bind.TypeAdapters$28.write(TypeAdapters.java:846)
        at com.google.gson.internal.bind.TypeAdapters$28.write(TypeAdapters.java:838)
        at com.google.gson.internal.bind.TypeAdapters$28.write(TypeAdapters.java:846)
        at com.google.gson.internal.bind.TypeAdapters$28.write(TypeAdapters.java:838)
        at com.google.gson.internal.bind.TypeAdapters$28.write(TypeAdapters.java:846)
        at com.google.gson.internal.bind.TypeAdapters$28.write(TypeAdapters.java:846)
        at com.google.gson.internal.bind.TypeAdapters$28.write(TypeAdapters.java:846)
        at com.google.gson.internal.bind.TypeAdapters$28.write(TypeAdapters.java:838)
        at com.google.gson.internal.bind.TypeAdapters$28.write(TypeAdapters.java:846)
        at com.google.gson.internal.bind.TypeAdapters$28.write(TypeAdapters.java:846)
        at com.google.gson.internal.bind.TypeAdapters$28.write(TypeAdapters.java:838)
        at com.google.gson.internal.bind.TypeAdapters$28.write(TypeAdapters.java:846)
        at com.google.gson.internal.bind.TypeAdapters$28.write(TypeAdapters.java:725)
        at com.google.gson.internal.Streams.write(Streams.java:73)
        at com.google.gson.JsonElement.toString(JsonElement.java:323)
        at org.ballerinalang.observability.anaylze.DefaultObservabilitySymbolCollector.generateSyntaxTreeJsonString(DefaultObservabilitySymbolCollector.java:208)
        at org.ballerinalang.observability.anaylze.DefaultObservabilitySymbolCollector.process(DefaultObservabilitySymbolCollector.java:92)
        at io.ballerina.projects.JBallerinaBackend.<init>(JBallerinaBackend.java:140)
        at io.ballerina.projects.JBallerinaBackend.lambda$from$0(JBallerinaBackend.java:121)
        at io.ballerina.projects.JBallerinaBackend$$Lambda$523/0x0000000301363148.apply(Unknown Source)
        at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1228)

As a temporary measure, you can increase the max heap size allocated to the Ballerina Java process.

@KavinduZoysa KavinduZoysa self-assigned this Dec 15, 2023
@NipunaMadhushan
Copy link
Contributor

This is related to issue #41725. This has been fixed with 2201.8.3 version along with PR #41569

@nipunayf nipunayf added Area/Compiler Team/Observability Observability in general, Metrics, Tracing & Logging and removed Team/LanguageServer Language Server Implementation related issues. #Compiler Area/Compiler labels Dec 15, 2023
@nipunayf
Copy link
Contributor

nipunayf commented Dec 15, 2023

I am using 2201.8.4, and still, the issue exists. However, we can build the project by disabling observabilityIncluded in the Ballerina.toml as a temporary measure.

@KavinduZoysa
Copy link
Contributor

KavinduZoysa commented Dec 15, 2023

The issue happens at this point.

https://github.com/ballerina-platform/ballerina-lang/blob/master/misc/observability-symbol-collector/src/main/java/org/ballerinalang/observability/anaylze/DefaultObservabilitySymbolCollector.java#L208

According to this example, at this point, the syntax tree JSON element of types.bal is converted to a string using toString(). types.bal file containing 37403 lines.

Also, at this point, we can see a spike in memory usage in visualVM.

Peek.2023-12-15.15-06.mp4

@NipunaMadhushan
Copy link
Contributor

Seems like the above fix (#41569) I mentioned, is still not enough for this use case.

@KavinduZoysa KavinduZoysa removed their assignment Dec 15, 2023
@KavinduZoysa
Copy link
Contributor

One thing we can do here is to split large files into separate files. In this case, we have to do that from the open API side.

Another one is,
Here we use StringBuilder to get the JSON format of the syntax tree to write to a file. We can keep the JsonElement as it is and write element by element into the file(We may need a separate method for that). Still, there is a possibility for OOM because JsonElement is exponentially large.

@NipunaMadhushan, @lnash94, @Nuvindu

@Nuvindu
Copy link
Contributor Author

Nuvindu commented Dec 18, 2023

@KavinduZoysa I have manually split the types.bal file into separate files. It fixes the lang server shutting down issue but still the same out of memory issue will occur when building the ballerina project.
P.S. Currently building the project by setting the observabilityIncluded to false in the Ballerina.toml file

@KavinduZoysa
Copy link
Contributor

@KavinduZoysa I have manually split the types.bal file into separate files. It fixes the lang server shutting down issue but still the same out of memory issue will occur when building the ballerina project.

Can you please attach your project?

@Nuvindu
Copy link
Contributor Author

Nuvindu commented Dec 18, 2023

@KavinduZoysa You can download the project from here

@NipunaMadhushan
Copy link
Contributor

There is an issue created to fix this #42001.

This has been fixed with #42002.

@Nuvindu Nuvindu closed this as completed Apr 1, 2024
Copy link

github-actions bot commented Apr 1, 2024

This issue is NOT closed with a proper Reason/ label. Make sure to add proper reason label before closing. Please add or leave a comment with the proper reason label now.

      - Reason/EngineeringMistake - The issue occurred due to a mistake made in the past.
      - Reason/Regression - The issue has introduced a regression.
      - Reason/MultipleComponentInteraction - Issue occured due to interactions in multiple components.
      - Reason/Complex - Issue occurred due to complex scenario.
      - Reason/Invalid - Issue is invalid.
      - Reason/Other - None of the above cases.

@nipunayf nipunayf added the Reason/Other None of the other reasons. label Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix/Crash All issues caused by NPE, CCE, etc Reason/Other None of the other reasons. Team/Observability Observability in general, Metrics, Tracing & Logging Type/Bug
Projects
Archived in project
Development

No branches or pull requests

6 participants