Skip to content

Commit

Permalink
Set the ulimit for plugin processes, respecting env var STEAMPIPE_ULI…
Browse files Browse the repository at this point in the history
…MIT. Closes #43
  • Loading branch information
kaidaguerre committed Feb 23, 2021
1 parent 54e5936 commit 7748669
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"context"
"fmt"
"log"
"os"
"strconv"
"syscall"

"github.com/hashicorp/go-hclog"
"github.com/turbot/steampipe-plugin-sdk/grpc"
Expand Down Expand Up @@ -41,6 +44,30 @@ func (p *Plugin) Initialise() {
log.SetOutput(p.Logger.StandardWriter(&hclog.StandardLoggerOptions{InferLevels: true}))
log.SetPrefix("")
log.SetFlags(0)

// set file limit
p.setuLimit()
}

const uLimitEnvVar = "STEAMPIPE_ULIMIT"
const uLimitDefault = 2560

func (p *Plugin) setuLimit() {
var ulimit uint64 = uLimitDefault
if ulimitString, ok := os.LookupEnv(uLimitEnvVar); ok {
if ulimitEnv, err := strconv.ParseUint(ulimitString, 10, 64); err == nil {
ulimit = ulimitEnv
}
}

var rLimit syscall.Rlimit
rLimit.Max = ulimit
rLimit.Cur = ulimit
p.Logger.Info("Setting Ulimit", "ulimit", ulimit)
err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
p.Logger.Error("Error Setting Ulimit", "error", err)
}
}

func (p *Plugin) GetSchema() (map[string]*proto.TableSchema, error) {
Expand Down

0 comments on commit 7748669

Please sign in to comment.