fix(dev): raise macOS open-file limit before astro dev to prevent EMFILE

This commit is contained in:
Davide Scaini
2026-04-26 21:16:33 +02:00
parent cbe3e0eeaf
commit 1c9b89cd1c
+10
View File
@@ -7,6 +7,8 @@ foreground. One command replaces the two-terminal setup.
from __future__ import annotations from __future__ import annotations
import os import os
import platform
import resource
import subprocess import subprocess
import sys import sys
import threading import threading
@@ -233,6 +235,14 @@ def dev(
"VITE_API_PORT": str(api_port), # picked up by astro.config.mjs "VITE_API_PORT": str(api_port), # picked up by astro.config.mjs
} }
# Astro's file watcher opens many handles; macOS defaults to 256, which
# causes EMFILE. Raise the limit before forking so the child inherits it.
if platform.system() == "Darwin":
target = 65536
soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
if soft < target:
resource.setrlimit(resource.RLIMIT_NOFILE, (min(target, hard), hard))
# Start astro dev in foreground (Ctrl+C stops everything) # Start astro dev in foreground (Ctrl+C stops everything)
console.print(f"Starting [cyan]astro dev[/cyan] on port {port}") console.print(f"Starting [cyan]astro dev[/cyan] on port {port}")
console.print() console.print()