Skip to content

Commit

Permalink
Merge pull request #244 from opentofu/rlimit
Browse files Browse the repository at this point in the history
Added automatic rlimit handling
  • Loading branch information
abstractionfactory authored Nov 12, 2024
2 parents 25eb5eb + 99108ce commit 122dfe3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions backend/cmd/generate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ func main() {

ctx := context.Background()

if err := setRLimit(ctx, mainLogger); err != nil {
mainLogger.Error(ctx, err.Error())
os.Exit(1)
}

approvedLicenses, err := readLicensesFile(ctx, licensesFile)
if err != nil {
mainLogger.Error(ctx, err.Error())
Expand Down
21 changes: 21 additions & 0 deletions backend/cmd/generate/rlimit_nonwindows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//go:build !windows

package main

import (
"context"
"syscall"

"github.com/opentofu/libregistry/logger"
)

func setRLimit(ctx context.Context, log logger.Logger) error {
log.Info(ctx, "Setting maximum number of file descriptors to 50000...")
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &syscall.Rlimit{
Cur: 50000,
Max: 50000,
}); err != nil {
log.Warn(ctx, "Failed to set rlimit, generation may fail on larger repositories (%v)", err)
}
return nil
}
7 changes: 7 additions & 0 deletions backend/cmd/generate/rlimit_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build windows

package main

func setRLimit(ctx context.Context, log logger.Logger) error {
return nil
}

0 comments on commit 122dfe3

Please sign in to comment.