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

Don't divide CODEQL_RAM in half #16780

Open
mat-sylvia-mark43 opened this issue Jun 18, 2024 · 8 comments
Open

Don't divide CODEQL_RAM in half #16780

mat-sylvia-mark43 opened this issue Jun 18, 2024 · 8 comments
Assignees
Labels
enhancement New feature or request JS question Further information is requested

Comments

@mat-sylvia-mark43
Copy link

This code in the autobuild.sh script halves memory between the JVM and TS:

# If CODEQL_RAM is set, use half for Java and half for TS.
if [ -n "${CODEQL_RAM:-}" ] ; then
half_ram="$(( CODEQL_RAM / 2 ))"
LGTM_TYPESCRIPT_RAM="$half_ram"
export LGTM_TYPESCRIPT_RAM
jvm_args="$jvm_args -Xmx${half_ram}m"
fi

Since CODEQL_RAM appears to be a default variable, consuming most of the Github runner's memory, this script shouldn't be halving the memory allocation as large TS projects hit a FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory error. How can we override this halving?

@mat-sylvia-mark43 mat-sylvia-mark43 added the question Further information is requested label Jun 18, 2024
@mbg
Copy link
Member

mbg commented Jun 19, 2024

Hi @mat-sylvia-mark43 👋

Thanks for raising this. I can see that we recently open-sourced this file, but that it has implemented this behaviour since we added support for JS/TS years ago.

I don't think there is a good way to override this behaviour and it may be a sign that the runner you are using does not have enough memory for the project you are trying to analyse. I.e. it is possible that allocating more memory for TS and less for the JVM will just result in an out-of-memory error elsewhere/in the JVM instead.

However, I am checking this with the relevant engineering team to see if this halving is still appropriate for our needs today. I or one of them will get back to you here once we have looked into this.

@mat-sylvia-mark43
Copy link
Author

@mbg Thanks for the details! I can see that codeql is setting: CODEQL_RAM: 29537 and the runner for this has 32GB of memory.

I don't have the option of trying a bigger size runner at this time. Also, this project succeeds in GHA workflows where CodeQL isn't present/conducing a scan...so I really think I need to be able to control/override that dividing logic.

@mbg
Copy link
Member

mbg commented Jun 21, 2024

@mat-sylvia-mark43 Thanks for the update! The team discussed this issue and is considering the addition of new environment variable(s) that would allow overriding the default memory halving behaviour. I will post an update here once we have something more concrete.

Also, this project succeeds in GHA workflows where CodeQL isn't present/conducing a scan

CodeQL generally requires more memory than an ordinary build, because of the extra work needed to produce the database. So whether or not a build succeeds without CodeQL present isn't a good indicator for whether it will work on a given machine once CodeQL is enabled.

@mat-sylvia-mark43
Copy link
Author

@mbg Thanks! I see your WIP PR also. I'd love to test this if we can somehow orchestrate that.

@mat-sylvia-mark43
Copy link
Author

@mbg This OOM issue may be bigger than just this original concern. For example, an 8KB tsx file (FailingOnThisFile.tsx) is making codeql run out of memory. This is the CodeQL analyze log (ubuntu-latest runner = 7GB memory):

[2024-06-25 19:09:43] [build-stdout] Done opening project /home/runner/work/...../tsconfig.json (5254 ms)
  [2024-06-25 19:09:43] [build-stdout] Extracting /home/runner/work/..../FailingOnThisFile.tsx
  [2024-06-25 19:11:02] [build-stderr] <--- Last few GCs --->
  [2024-06-25 19:11:02] [build-stderr] [2337:0x54898b0]    81539 ms: Mark-sweep (reduce) 3835.6 (3899.5) -> 3834.8 (3899.8) MB, 3377.4 / 0.0 ms  (average mu = 0.133, current mu = 0.002) allocation failure; scavenge might not succeed
  [2024-06-25 19:11:02] [build-stderr] [2337:0x54[89](https://github.com/mark43/.../actions/runs/9668023328/job/26671826284#step:5:90)8b0]    84915 ms: Mark-sweep (reduce) 3834.9 (3899.8) -> 3834.8 (3900.0) MB, 3375.7 / 0.0 ms  (average mu = 0.069, current mu = 0.000) allocation failure; GC in old space requested
  [2024-06-25 19:11:02] [build-stderr] <--- JS stacktrace --->
  [2024-06-25 19:11:02] [build-stderr] FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

Note that I redacted some details out of this log.

@mbg
Copy link
Member

mbg commented Jun 26, 2024

Thanks for the extra information, @mat-sylvia-mark43!

Can you confirm that you run out of memory just with this one file? If so, could you share the file with us or see if you can find a minimal example that reproduces the issue?

@mat-sylvia-mark43
Copy link
Author

@mbg Yes, it does indeed run out of memory on this file as the logs above attest to (extracting...then OOM). I can't share this file unfortunately.

@mbg
Copy link
Member

mbg commented Jun 28, 2024

What I'm trying to establish is whether there is a problem with this specific file or the project more generally. The log doesn't quite answer that since the whole project is being extracted and it could be that this file just happens to push things over the edge because it's a big project. Alternatively, there could be something specifically wrong with how we extract this file. The way to answer this would be to run an analysis with just this file in the workspace and see whether that also causes an OOM condition or not.

If that confirms that this specific file is responsible and you cannot share that file, then the options you have are:

  • If there is something obviously unusual about the file (size, language feature that's only used in this file, etc.), you could let us know here.
  • You could comment out the contents of the file and see if that causes the analysis to succeed. If it does, uncomment parts of the file bit by bit until the analysis fails again. Repeat this process until you have a minimal part of the file which causes the problem and share that with us.
  • You could open a support ticket and share the file with us there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request JS question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants