Skip to content

reuseport: env var to turn it off #1038

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

Merged
merged 1 commit into from
Apr 8, 2015
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
2 changes: 1 addition & 1 deletion p2p/net/conn/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (d *Dialer) rawConnDial(ctx context.Context, raddr ma.Multiaddr, remote pee
// make a copy of the manet.Dialer, we may need to change its timeout.
madialer := d.Dialer

if laddr != nil && reuseport.Available() {
if laddr != nil && reuseportIsAvailable() {
// we're perhaps going to dial twice. half the timeout, so we can afford to.
// otherwise our context would expire right after the first dial.
madialer.Dialer.Timeout = (madialer.Dialer.Timeout / 2)
Expand Down
2 changes: 1 addition & 1 deletion p2p/net/conn/listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func manetListen(addr ma.Multiaddr) (manet.Listener, error) {
return nil, err
}

if reuseport.Available() {
if reuseportIsAvailable() {
nl, err := reuseport.Listen(network, naddr)
if err == nil {
// hey, it worked!
Expand Down
35 changes: 35 additions & 0 deletions p2p/net/conn/reuseport.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package conn

import (
"os"
"strings"

reuseport "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-reuseport"
)

// envReuseport is the env variable name used to turn off reuse port.
// It default to true.
const envReuseport = "IPFS_REUSEPORT"

// envReuseportVal stores the value of envReuseport. defaults to true.
var envReuseportVal = true

func init() {
v := strings.ToLower(os.Getenv(envReuseport))
if v == "false" || v == "f" || v == "0" {
envReuseportVal = false
log.Infof("REUSEPORT disabled (IPFS_REUSEPORT=%s)", v)
}
}

// reuseportIsAvailable returns whether reuseport is available to be used. This
// is here because we want to be able to turn reuseport on and off selectively.
// For now we use an ENV variable, as this handles our pressing need:
//
// IPFS_REUSEPORT=false ipfs daemon
//
// If this becomes a sought after feature, we could add this to the config.
// In the end, reuseport is a stop-gap.
func reuseportIsAvailable() bool {
return envReuseportVal && reuseport.Available()
}