chore(ulimit): handle low ulimit value on shell session for POSIX if max open files is below 4096 (#3601)

This commit is contained in:
Sergio Garcia
2024-03-27 14:52:14 +01:00
committed by GitHub
parent 522aeebe5e
commit c03f959005
+6 -3
View File
@@ -7,6 +7,7 @@ import shutil
import sys
import traceback
from pkgutil import walk_packages
from resource import setrlimit
from types import ModuleType
from typing import Any
@@ -448,11 +449,13 @@ def execute_checks(
from resource import RLIMIT_NOFILE, getrlimit
# Check ulimit for the maximum system open files
soft, _ = getrlimit(RLIMIT_NOFILE)
soft, hard = getrlimit(RLIMIT_NOFILE)
if soft < 4096:
logger.warning(
f"Your session file descriptors limit ({soft} open files) is below 4096. We recommend to increase it to avoid errors. Solve it running this command `ulimit -n 4096`. For more info visit https://docs.prowler.cloud/en/latest/troubleshooting/"
logger.info(
f"Your session file descriptors limit ({soft} open files) is below 4096. Updating file descriptors session limit to 4096 during execution only."
)
# Set the soft ulimit to 4096
setrlimit(RLIMIT_NOFILE, (4096, hard))
except Exception as error:
logger.error("Unable to retrieve ulimit default settings")
logger.error(