Skip to content

Commit

Permalink
test - disable rsm
Browse files Browse the repository at this point in the history
  • Loading branch information
mudler committed Feb 2, 2022
1 parent b237748 commit d96ee12
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 12 deletions.
39 changes: 28 additions & 11 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/libp2p/go-libp2p"
connmanager "github.com/libp2p/go-libp2p-connmgr"
dht "github.com/libp2p/go-libp2p-kad-dht"
rcmgr "github.com/libp2p/go-libp2p-resource-manager"
"github.com/mudler/edgevpn/pkg/blockchain"
"github.com/mudler/edgevpn/pkg/crypto"
"github.com/mudler/edgevpn/pkg/discovery"
Expand Down Expand Up @@ -201,17 +200,35 @@ func (c Config) ToOpts(l *logger.Logger) ([]node.Option, []vpn.Option, error) {

libp2pOpts = append(libp2pOpts, libp2p.ConnectionManager(cm))

// XXX: Currently, when RSM is enabled, the following happens randomly.
// As a workaround, disable RSM.
// panic: runtime error: invalid memory address or nil pointer dereference
// [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xcc3205]
// goroutine 150339 [running]:
// github.com/libp2p/go-libp2p-resource-manager.(*peerScope).ReserveMemory(0x0, 0x40000, 0xc00433deff, 0x0, 0x20)
// <autogenerated>:1 +0x5
// github.com/libp2p/go-yamux/v3.(*Session).incomingStream(0xc004339200, 0x2, 0x0, 0x0)
// /home/runner/go/pkg/mod/github.com/libp2p/go-yamux/v3@v3.0.2/session.go:765 +0x98
// github.com/libp2p/go-yamux/v3.(*Session).handleStreamMessage(0xc004339200, 0x200000001000100, 0xc000000000, 0xc, 0xc)
// /home/runner/go/pkg/mod/github.com/libp2p/go-yamux/v3@v3.0.2/session.go:660 +0x61a
// github.com/libp2p/go-yamux/v3.(*Session).recvLoop(0xc004339200, 0x0, 0x0)
// /home/runner/go/pkg/mod/github.com/libp2p/go-yamux/v3@v3.0.2/session.go:648 +0x1a5
// github.com/libp2p/go-yamux/v3.(*Session).recv(0xc004339200)
// /home/runner/go/pkg/mod/github.com/libp2p/go-yamux/v3@v3.0.2/session.go:602 +0x2b
// created by github.com/libp2p/go-yamux/v3.newSession
// /home/runner/go/pkg/mod/github.com/libp2p/go-yamux/v3@v3.0.2/session.go:157 +0x449
if c.LowProfile {
limiter := rcmgr.NewDefaultLimiter()
libp2p.SetDefaultServiceLimits(limiter)
mgr, err := rcmgr.NewResourceManager(limiter)
if err != nil {
llger.Fatal("could not create connection manager")
}

limiter.SystemLimits = limiter.SystemLimits.WithConnLimit(512, 512, 1024)
limiter.DefaultPeerLimits = limiter.DefaultPeerLimits.WithConnLimit(16, 16, 32)
libp2pOpts = append(libp2pOpts, libp2p.ResourceManager(mgr))
// TODO: Re-enable and tweak below when RSM is stable
//limiter := rcmgr.NewDefaultLimiter()
//libp2p.SetDefaultServiceLimits(limiter)
//mgr, err := rcmgr.NewResourceManager(limiter)
//if err != nil {
// llger.Fatal("could not create connection manager")
//}

//limiter.SystemLimits = limiter.SystemLimits.WithConnLimit(512, 512, 1024)
//limiter.DefaultPeerLimits = limiter.DefaultPeerLimits.WithConnLimit(16, 16, 32)
//libp2pOpts = append(libp2pOpts, libp2p.ResourceManager(mgr))
}

if c.Connection.HolePunch {
Expand Down
4 changes: 3 additions & 1 deletion pkg/node/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (e *Node) genHost(ctx context.Context) (host.Host, error) {
return nil, err
}

opts := append(e.config.Options, libp2p.FallbackDefaults)
opts := e.config.Options

cg, err := conngater.NewBasicConnectionGater(nil)
if err != nil {
Expand Down Expand Up @@ -109,6 +109,8 @@ func (e *Node) genHost(ctx context.Context) (host.Host, error) {
opts = append(opts, libp2p.NoSecurity)
}

opts = append(opts, fallbackDefaults)

return libp2p.New(opts...)
}

Expand Down
60 changes: 60 additions & 0 deletions pkg/node/defaults.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package node

import "github.com/libp2p/go-libp2p"

// XXX:
// This is a slightly re-adaptation of
// https://github.com/libp2p/go-libp2p/blob/0c7ce330810603728f9be66d998450d0fbfb8df7/defaults.go#L113
// as the fallback usually is totally fine, currently, when RSM is enabled a panic happens randomly.
// As a workaround, disable RSM from fallback configs, while keep all the rest intact in the hope
// to drop this with libp2p.FallbackDefaults
var defaults = []struct {
fallback func(cfg *libp2p.Config) bool
opt libp2p.Option
}{
{
fallback: func(cfg *libp2p.Config) bool { return cfg.Transports == nil && cfg.ListenAddrs == nil },
opt: libp2p.DefaultListenAddrs,
},
{
fallback: func(cfg *libp2p.Config) bool { return cfg.Transports == nil },
opt: libp2p.DefaultTransports,
},
{
fallback: func(cfg *libp2p.Config) bool { return cfg.Muxers == nil },
opt: libp2p.DefaultMuxers,
},
{
fallback: func(cfg *libp2p.Config) bool { return !cfg.Insecure && cfg.SecurityTransports == nil },
opt: libp2p.DefaultSecurity,
},
{
fallback: func(cfg *libp2p.Config) bool { return cfg.PeerKey == nil },
opt: libp2p.RandomIdentity,
},
{
fallback: func(cfg *libp2p.Config) bool { return cfg.Peerstore == nil },
opt: libp2p.DefaultPeerstore,
},
{
fallback: func(cfg *libp2p.Config) bool { return !cfg.RelayCustom },
opt: libp2p.DefaultEnableRelay,
},

{
fallback: func(cfg *libp2p.Config) bool { return cfg.ConnManager == nil },
opt: libp2p.DefaultConnectionManager,
},
}

var fallbackDefaults libp2p.Option = func(cfg *libp2p.Config) error {
for _, def := range defaults {
if !def.fallback(cfg) {
continue
}
if err := cfg.Apply(def.opt); err != nil {
return err
}
}
return nil
}

0 comments on commit d96ee12

Please sign in to comment.