Repository: projectdiscovery/nuclei

Issue:
Functional tests failing on OSX (CI) environment
## Description
Ref: https://github.com/projectdiscovery/nuclei/actions/runs/14775733517/job/41484164953?pr=6204

Hints from issue comments:
@ehsandeep: @dwisiswant0 this is stil happening on latest PRs.@dwisiswant0: i’m finding it really difficult to debug this issue because it’s platform specific, and i'm not using a macOS environment to properly replicate it. trying to troubleshoot it through CI alone doesn’t seem practical either, as it’s hard to test iterative fixes effectively.

Solution patch:
diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml
index af6ad9d7..7cbfd2f1 100644
--- a/.github/workflows/tests.yaml
+++ b/.github/workflows/tests.yaml
@@ -94,7 +94,7 @@ jobs:
       - uses: actions/checkout@v4
       - uses: projectdiscovery/actions/setup/go@v1
       - uses: projectdiscovery/actions/setup/python@v1
-      - run: bash run.sh "${{ matrix.os }}"
+      - run: bash run.sh
         env:
           GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
         working-directory: cmd/functional-test/



Test patch:
diff --git a/cmd/functional-test/main.go b/cmd/functional-test/main.go
index 8a5cebc5..78114fdb 100644
--- a/cmd/functional-test/main.go
+++ b/cmd/functional-test/main.go
@@ -27,7 +27,7 @@ var (
 func main() {
 	flag.Parse()
 
-	debug := os.Getenv("DEBUG") == "true"
+	debug := os.Getenv("DEBUG") == "true" || os.Getenv("RUNNER_DEBUG") == "1"
 
 	if err, errored := runFunctionalTests(debug); err != nil {
 		log.Fatalf("Could not run functional tests: %s\n", err)
diff --git a/cmd/functional-test/run.sh b/cmd/functional-test/run.sh
index a3caf722..a955ad8a 100755
--- a/cmd/functional-test/run.sh
+++ b/cmd/functional-test/run.sh
@@ -1,27 +1,43 @@
 #!/bin/bash
 
-# reading os type from arguments
-CURRENT_OS=$1
+if [ "${RUNNER_OS}" == "Windows" ]; then
+    EXT=".exe"
+elif [ "${RUNNER_OS}" == "macOS" ]; then
+    if [ "${CI}" == "true" ]; then
+        sudo sysctl -w kern.maxfiles{,perproc}=524288
+        sudo launchctl limit maxfiles 65536 524288
+    fi
 
-if [ "${CURRENT_OS}" == "windows-latest" ];then
-    extension=.exe
+    ORIGINAL_ULIMIT="$(ulimit -n)"
+    ulimit -n 65536 || true
 fi
 
+mkdir -p .nuclei-config/nuclei/
+touch .nuclei-config/nuclei/.nuclei-ignore
+
 echo "::group::Building functional-test binary"
-go build -o functional-test$extension
+go build -o "functional-test${EXT}"
 echo "::endgroup::"
 
 echo "::group::Building Nuclei binary from current branch"
-go build -o nuclei_dev$extension ../nuclei
+go build -o "nuclei-dev${EXT}" ../nuclei
+echo "::endgroup::"
+
+echo "::group::Building latest release of nuclei"
+go build -o "nuclei${EXT}" -v github.com/projectdiscovery/nuclei/v3/cmd/nuclei
 echo "::endgroup::"
 
 echo "::group::Installing nuclei templates"
-./nuclei_dev$extension -update-templates
+eval "./nuclei-dev${EXT} -update-templates"
 echo "::endgroup::"
 
-echo "::group::Building latest release of nuclei"
-go build -o nuclei$extension -v github.com/projectdiscovery/nuclei/v3/cmd/nuclei
+echo "::group::Validating templates"
+eval "./nuclei-dev${EXT} -validate"
 echo "::endgroup::"
 
-echo 'Starting Nuclei functional test'
-./functional-test$extension -main ./nuclei$extension -dev ./nuclei_dev$extension -testcases testcases.txt
+echo "Starting Nuclei functional test"
+eval "./functional-test${EXT} -main ./nuclei${EXT} -dev ./nuclei-dev${EXT} -testcases testcases.txt"
+
+if [ "${RUNNER_OS}" == "macOS" ]; then
+    ulimit -n "${ORIGINAL_ULIMIT}" || true
+fi