From fd6b617ad5ee1f6e50f4093eb6085e19a2d57894 Mon Sep 17 00:00:00 2001 From: Raphael Amorim Date: Mon, 15 Sep 2025 14:03:59 +0200 Subject: [PATCH] fix: remove ulimt as go 1.19 automatically raises file descriptors --- internal/lsp/watcher/ulimit_bsd.go | 25 ---------------- internal/lsp/watcher/ulimit_darwin.go | 24 ---------------- internal/lsp/watcher/ulimit_fallback.go | 8 ------ internal/lsp/watcher/ulimit_linux.go | 25 ---------------- internal/lsp/watcher/ulimit_windows.go | 38 ------------------------- internal/lsp/watcher/watcher.go | 7 ----- 6 files changed, 127 deletions(-) delete mode 100644 internal/lsp/watcher/ulimit_bsd.go delete mode 100644 internal/lsp/watcher/ulimit_darwin.go delete mode 100644 internal/lsp/watcher/ulimit_fallback.go delete mode 100644 internal/lsp/watcher/ulimit_linux.go delete mode 100644 internal/lsp/watcher/ulimit_windows.go diff --git a/internal/lsp/watcher/ulimit_bsd.go b/internal/lsp/watcher/ulimit_bsd.go deleted file mode 100644 index 816e82adee5e57341b7e392e117b245a7ca4a0dc..0000000000000000000000000000000000000000 --- a/internal/lsp/watcher/ulimit_bsd.go +++ /dev/null @@ -1,25 +0,0 @@ -//go:build freebsd || openbsd || netbsd || dragonfly - -package watcher - -import "syscall" - -func Ulimit() (uint64, error) { - var currentLimit uint64 = 0 - var rLimit syscall.Rlimit - err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit) - if err != nil { - return 0, err - } - currentLimit = uint64(rLimit.Cur) - rLimit.Cur = rLimit.Max / 10 * 8 - err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit) - if err != nil { - return currentLimit, err - } - err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit) - if err != nil { - return currentLimit, err - } - return uint64(rLimit.Cur), nil -} diff --git a/internal/lsp/watcher/ulimit_darwin.go b/internal/lsp/watcher/ulimit_darwin.go deleted file mode 100644 index a53f143bd0341e5fc7ac95441c2246eb7ffb2ccb..0000000000000000000000000000000000000000 --- a/internal/lsp/watcher/ulimit_darwin.go +++ /dev/null @@ -1,24 +0,0 @@ -//go:build darwin - -package watcher - -import "syscall" - -func Ulimit() (uint64, error) { - var rLimit syscall.Rlimit - err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit) - if err != nil { - return 0, err - } - currentLimit := rLimit.Cur - rLimit.Cur = rLimit.Max / 10 * 8 - err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit) - if err != nil { - return currentLimit, err - } - err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit) - if err != nil { - return currentLimit, err - } - return rLimit.Cur, nil -} diff --git a/internal/lsp/watcher/ulimit_fallback.go b/internal/lsp/watcher/ulimit_fallback.go deleted file mode 100644 index 118554f25a34aa5921b1773c72d87dc3975324a7..0000000000000000000000000000000000000000 --- a/internal/lsp/watcher/ulimit_fallback.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:build !linux && !darwin && !freebsd && !openbsd && !netbsd && !dragonfly && !windows - -package watcher - -func Ulimit() (uint64, error) { - // Fallback for exotic systems - return a reasonable default - return 2048, nil -} diff --git a/internal/lsp/watcher/ulimit_linux.go b/internal/lsp/watcher/ulimit_linux.go deleted file mode 100644 index 298fcad96710eb106ee607ac823962450f892bf3..0000000000000000000000000000000000000000 --- a/internal/lsp/watcher/ulimit_linux.go +++ /dev/null @@ -1,25 +0,0 @@ -//go:build linux - -package watcher - -import "syscall" - -func Ulimit() (uint64, error) { - var currentLimit uint64 = 0 - var rLimit syscall.Rlimit - err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit) - if err != nil { - return 0, err - } - currentLimit = rLimit.Cur - rLimit.Cur = rLimit.Max / 10 * 8 - err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit) - if err != nil { - return currentLimit, err - } - err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit) - if err != nil { - return currentLimit, err - } - return rLimit.Cur, nil -} diff --git a/internal/lsp/watcher/ulimit_windows.go b/internal/lsp/watcher/ulimit_windows.go deleted file mode 100644 index 14afbabeea1ce4818bb59a3fc8c5e2ee1fa8432a..0000000000000000000000000000000000000000 --- a/internal/lsp/watcher/ulimit_windows.go +++ /dev/null @@ -1,38 +0,0 @@ -//go:build windows - -package watcher - -import ( - "syscall" - "unsafe" - - "golang.org/x/sys/windows" -) - -var ( - kernel32 = windows.NewLazyDLL("kernel32.dll") - procGetProcessHandleCount = kernel32.NewProc("GetProcessHandleCount") -) - -func Ulimit() (uint64, error) { - // Windows doesn't have the same file descriptor limits as Unix systems - // Instead, we can get the current handle count for monitoring purposes - currentProcess := windows.CurrentProcess() - - var handleCount uint32 - ret, _, err := procGetProcessHandleCount.Call( - uintptr(currentProcess), - uintptr(unsafe.Pointer(&handleCount)), - ) - - if ret == 0 { - // If the call failed, return a reasonable default - if err != syscall.Errno(0) { - return 2048, nil - } - } - - // Windows typically allows much higher handle counts than Unix file descriptors - // Return the current count, which serves as a baseline for monitoring - return uint64(handleCount), nil -} diff --git a/internal/lsp/watcher/watcher.go b/internal/lsp/watcher/watcher.go index 139d144e1e5c65c11962e73201b42b15cd09f98a..18b790349a10f0827f45f8ccb9fb6968980a9d4e 100644 --- a/internal/lsp/watcher/watcher.go +++ b/internal/lsp/watcher/watcher.go @@ -28,13 +28,6 @@ type Client struct { registrations *csync.Slice[protocol.FileSystemWatcher] } -func init() { - // Ensure the watcher is initialized with a reasonable file limit - if _, err := Ulimit(); err != nil { - slog.Error("Error setting file limit", "error", err) - } -} - // New creates a new workspace watcher for the given client. func New(name string, client *lsp.Client) *Client { return &Client{