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

source= directive on 4000 LOC drains 64GB RAM and trigger OOM #3177

Open
dezza opened this issue Mar 28, 2025 · 6 comments
Open

source= directive on 4000 LOC drains 64GB RAM and trigger OOM #3177

dezza opened this issue Mar 28, 2025 · 6 comments

Comments

@dezza
Copy link

dezza commented Mar 28, 2025

$ shellcheck --version
ShellCheck - shell script analysis tool
version: 0.10.0
license: GNU General Public License, version 3
website: https://www.shellcheck.net

I had this snippet in my bashrc.

#!/bin/bash
export NVM_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/nvm"

# shellcheck source=/home/dza/.local/config/nvm/nvm.sh
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"

With 64GB DDR5 in less than a minute;

mar 28 23:04:20 ocelot kernel: Out of memory: Killed process 41299 (shellcheck) total-vm:1073848180kB, anon-rss:1512428kB, file-rss:680kB, shmem-rss:0kB, UID:1000 pgtables:70180kB oom_score_adj:200

The LSP client in vim then restarted shellcheck and the same thing happened over and over.

I believe the 4000 LOC of nvm.sh
https://github.com/nvm-sh/nvm/blob/master/nvm.sh

Might be the trigger.

@wileyhy
Copy link

wileyhy commented Mar 30, 2025 via email

@PeterSaan
Copy link

Same problem here.
Neovim 0.11, Arch Linux.
When I open .bashrc and type anything that creates an error, the linter takes a bit of time to highlight it and afterwards it begins draining memory. I'll leave a screenshot that shows the procceses running.

Image

@koalaman
Copy link
Owner

Oof. The process is listed as using 1.5G (VIRT usage is 1T but that's lazily initialized), but I do see it spending 20 seconds and using 3G, and that would especially be a problem with some kind of LSP that invokes it repeatedly.

ShellCheck defaults to a whole-program iterative data flow analysis which in this case causes a very unfortunate memory explosion in in a file you don't even care about. To unblock this, you can add # shellcheck extended-analysis=false to your file.

@dezza
Copy link
Author

dezza commented Mar 31, 2025

@koalaman is this something that can be mitigated or handled properly differently? Like a timeout for completion, memory limit.

@koalaman
Copy link
Owner

@dezza The extended-analysis=false directive in a file or .shellcheckrc (or the flag --extended-analysis=false) will entirely mitigate this issue, dropping both the length processing time and the excessive memory usage.

There is a handful of checks that depends on this functionality and subsequently won't trigger, such as SC2317 "Command appears unreachable", SC2319 "$? refers to a condition", SC2324 "var+=1 will append, not increment" (the common denominator being that they require tracing the control flow of the script), but it beats the behavior as described.

I considered auto-disabling the functionality for especially large or cyclomatically complex scripts, but that runs into the issue of warnings suddenly vanishing when crossing the threshold.

@dezza
Copy link
Author

dezza commented Apr 2, 2025

@koalaman heh, I just tried to get bash-language-server to print any details, but it simply doesn't return any errors even on the highest BASH_IDE_LOG_LEVEL=debug with my https://github.com/yegappan/lsp lsp client also started in debug mode, restarted lsp everything..

I'm hoping there is a timeout in shellcheck, a sensible upper limit/timeout that can trigger an exit status that language servers can act on and relay to the lsp client itself. It doesn't seem like bash-language-server relays anything back to the client ?

If I run shellcheck -x myself over the file not much happens, it just eats RAM and CPU for over 3min by now.

I'm guessing the lsp clients kills it themselves because they have an upper limit. Maybe it would be an idea to enable such long processing explicitly with another argument or a repeated -xx argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants