Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try to raise ulimit if its too low #2466

Merged
merged 3 commits into from
Apr 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions cmd/ipfs/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const (
unrestrictedApiAccessKwd = "unrestricted-api"
unencryptTransportKwd = "disable-transport-encryption"
enableGCKwd = "enable-gc"
adjustFDLimitKwd = "manage-fdlimit"
// apiAddrKwd = "address-api"
// swarmAddrKwd = "address-swarm"
)
Expand Down Expand Up @@ -132,6 +133,7 @@ future version, along with this notice. Please move to setting the HTTP Headers.
cmds.BoolOption(unrestrictedApiAccessKwd, "Allow API access to unlisted hashes"),
cmds.BoolOption(unencryptTransportKwd, "Disable transport encryption (for debugging protocols)"),
cmds.BoolOption(enableGCKwd, "Enable automatic periodic repo garbage collection"),
cmds.BoolOption(adjustFDLimitKwd, "Check and raise file descriptor limits if needed"),

// TODO: add way to override addresses. tricky part: updating the config if also --init.
// cmds.StringOption(apiAddrKwd, "Address for the daemon rpc API (overrides config)"),
Expand All @@ -152,10 +154,19 @@ func defaultMux(path string) corehttp.ServeOption {
}
}

var fileDescriptorCheck = func() error { return nil }

func daemonFunc(req cmds.Request, res cmds.Response) {
// let the user know we're going.
fmt.Printf("Initializing daemon...\n")

managefd, _, _ := req.Option(adjustFDLimitKwd).Bool()
if managefd {
if err := fileDescriptorCheck(); err != nil {
log.Error("setting file descriptor limit: %s", err)
}
}

ctx := req.InvocContext()

go func() {
Expand Down
47 changes: 47 additions & 0 deletions cmd/ipfs/ulimit_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// +build linux darwin

package main

import (
"fmt"
"os"
"strconv"
"syscall"
)

var ipfsFileDescNum = uint64(2048)

func init() {
if val := os.Getenv("IPFS_FD_MAX"); val != "" {
n, err := strconv.Atoi(val)
if err != nil {
log.Error("bad value for IPFS_FD_MAX: %s", err)
} else {
ipfsFileDescNum = uint64(n)
}
}
fileDescriptorCheck = checkAndSetUlimit
}

func checkAndSetUlimit() error {
var rLimit syscall.Rlimit
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
return fmt.Errorf("error getting rlimit: %s", err)
}

if rLimit.Cur < ipfsFileDescNum {
if rLimit.Max < ipfsFileDescNum {
rLimit.Max = ipfsFileDescNum
}
fmt.Printf("Adjusting current ulimit to %d.\n", ipfsFileDescNum)
rLimit.Cur = ipfsFileDescNum
}

err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
return fmt.Errorf("error setting ulimit: %s", err)
}

return nil
}
3 changes: 0 additions & 3 deletions test/sharness/t0061-daemon-opts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ test_init_ipfs

test_launch_ipfs_daemon --unrestricted-api --disable-transport-encryption

test_expect_success "convert addresses from multiaddrs" '
'

gwyaddr=$GWAY_ADDR
apiaddr=$API_ADDR

Expand Down