on main help sign in
fix: remove ulimt as go 1.19 automatically raises file descriptors
fd6b617Raphael Amorim
internal/lsp/watcher/ulimit_bsd.godeleted−25
@@ -1,25 +0,0 @@
1−//go:build freebsd || openbsd || netbsd || dragonfly
2−
3−package watcher
4−
5−import "syscall"
6−
7−func Ulimit() (uint64, error) {
8− var currentLimit uint64 = 0
9− var rLimit syscall.Rlimit
10− err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
11− if err != nil {
12− return 0, err
13− }
14− currentLimit = uint64(rLimit.Cur)
15− rLimit.Cur = rLimit.Max / 10 * 8
16− err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
17− if err != nil {
18− return currentLimit, err
19− }
20− err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
21− if err != nil {
22− return currentLimit, err
23− }
24− return uint64(rLimit.Cur), nil
25−}
internal/lsp/watcher/ulimit_darwin.godeleted−24
@@ -1,24 +0,0 @@
1−//go:build darwin
2−
3−package watcher
4−
5−import "syscall"
6−
7−func Ulimit() (uint64, error) {
8− var rLimit syscall.Rlimit
9− err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
10− if err != nil {
11− return 0, err
12− }
13− currentLimit := rLimit.Cur
14− rLimit.Cur = rLimit.Max / 10 * 8
15− err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
16− if err != nil {
17− return currentLimit, err
18− }
19− err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
20− if err != nil {
21− return currentLimit, err
22− }
23− return rLimit.Cur, nil
24−}
internal/lsp/watcher/ulimit_fallback.godeleted−8
@@ -1,8 +0,0 @@
1−//go:build !linux && !darwin && !freebsd && !openbsd && !netbsd && !dragonfly && !windows
2−
3−package watcher
4−
5−func Ulimit() (uint64, error) {
6− // Fallback for exotic systems - return a reasonable default
7− return 2048, nil
8−}
internal/lsp/watcher/ulimit_linux.godeleted−25
@@ -1,25 +0,0 @@
1−//go:build linux
2−
3−package watcher
4−
5−import "syscall"
6−
7−func Ulimit() (uint64, error) {
8− var currentLimit uint64 = 0
9− var rLimit syscall.Rlimit
10− err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
11− if err != nil {
12− return 0, err
13− }
14− currentLimit = rLimit.Cur
15− rLimit.Cur = rLimit.Max / 10 * 8
16− err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
17− if err != nil {
18− return currentLimit, err
19− }
20− err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
21− if err != nil {
22− return currentLimit, err
23− }
24− return rLimit.Cur, nil
25−}
internal/lsp/watcher/ulimit_windows.godeleted−38
@@ -1,38 +0,0 @@
1−//go:build windows
2−
3−package watcher
4−
5−import (
6− "syscall"
7− "unsafe"
8−
9− "golang.org/x/sys/windows"
10−)
11−
12−var (
13− kernel32 = windows.NewLazyDLL("kernel32.dll")
14− procGetProcessHandleCount = kernel32.NewProc("GetProcessHandleCount")
15−)
16−
17−func Ulimit() (uint64, error) {
18− // Windows doesn't have the same file descriptor limits as Unix systems
19− // Instead, we can get the current handle count for monitoring purposes
20− currentProcess := windows.CurrentProcess()
21−
22− var handleCount uint32
23− ret, _, err := procGetProcessHandleCount.Call(
24− uintptr(currentProcess),
25− uintptr(unsafe.Pointer(&handleCount)),
26− )
27−
28− if ret == 0 {
29− // If the call failed, return a reasonable default
30− if err != syscall.Errno(0) {
31− return 2048, nil
32− }
33− }
34−
35− // Windows typically allows much higher handle counts than Unix file descriptors
36− // Return the current count, which serves as a baseline for monitoring
37− return uint64(handleCount), nil
38−}
internal/lsp/watcher/watcher.go−7
@@ -28,13 +28,6 @@ type Client struct {
28 registrations *csync.Slice[protocol.FileSystemWatcher]
28 registrations *csync.Slice[protocol.FileSystemWatcher]
29}
29}
30
30
31−func init() {
32− // Ensure the watcher is initialized with a reasonable file limit
33− if _, err := Ulimit(); err != nil {
34− slog.Error("Error setting file limit", "error", err)
35− }
36−}
37−
38// New creates a new workspace watcher for the given client.
31// New creates a new workspace watcher for the given client.
39func New(name string, client *lsp.Client) *Client {
32func New(name string, client *lsp.Client) *Client {
40 return &Client{
33 return &Client{