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

"invalid memory address or nil pointer dereference" in echo example #263

Closed
masonforest opened this issue Jan 14, 2018 · 12 comments
Closed

Comments

@masonforest
Copy link

Hello, thanks for building libp2p! Decentralize the world! 😃

I'm getting an nil pointer dereference when I run the second instance of the echo example.

Steps to reproduce from a clean install:

go get -d github.com/libp2p/go-libp2p/...
cd $GOPATH/src/github.com/libp2p/go-libp2p
make
make deps
go build ./examples/echo
./echo -secio -l 10000
# with the correct multiaddress provided
./echo -l 10001 -d /ip4/127.0.0.1/tcp/10000/ipfs/QmR1HVuuKpQRH8sVTL5A9wdtAhtQzr7jixNvrcVL2BrVDe -secio

Here's the full traceback.

It looks like it has something to do with smuxConn not being set here?

Thanks again,

-Mason

@llgoer
Copy link

llgoer commented Jan 16, 2018

same error

2018/01/16 14:31:48 listening for connections
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x133ffda]

goroutine 32 [running]:
github.com/libp2p/go-peerstream.(*Swarm).NewStreamWithConn(0xc4201203c0, 0xc42014a000, 0xc4203fd700, 0x0, 0x95000000014ce50a)
/Users/me/Projects/Go/src/github.com/libp2p/go-peerstream/swarm.go:328 +0xba
github.com/libp2p/go-peerstream.(*Conn).NewStream(0xc42014a000, 0xc4203fd5e8, 0x1029f59, 0xc400000008)
/Users/me/Projects/Go/src/github.com/libp2p/go-peerstream/conn.go:143 +0x34
github.com/libp2p/go-libp2p-swarm.(*Conn).NewSwarmStream(0xc42014a000, 0xc4203fd5f8, 0xc4203fd600, 0xc420440340)
/Users/me/Projects/Go/src/github.com/libp2p/go-libp2p-swarm/swarm_conn.go:79 +0x2b
github.com/libp2p/go-libp2p-swarm.(*Conn).NewStream(0xc42014a000, 0x160f7d8, 0xc420072a20, 0xc4204403c8, 0xc42005f800)
/Users/me/Projects/Go/src/github.com/libp2p/go-libp2p-swarm/swarm_conn.go:85 +0x2b
github.com/libp2p/go-libp2p/p2p/protocol/identify.(*IDService).IdentifyConn(0xc420092de0, 0x182f5c0, 0xc42014a000)
/Users/me/Projects/Go/src/github.com/libp2p/go-libp2p/p2p/protocol/identify/id.go:88 +0x29e
github.com/libp2p/go-libp2p/p2p/host/basic.(*BasicHost).newConnHandler(0xc42014a400, 0x182f5c0, 0xc42014a000)
/Users/me/Projects/Go/src/github.com/libp2p/go-libp2p/p2p/host/basic/basic_host.go:227 +0xaf
github.com/libp2p/go-libp2p/p2p/host/basic.(*BasicHost).(github.com/libp2p/go-libp2p/p2p/host/basic.newConnHandler)-fm(0x182f5c0, 0xc42014a000)
/Users/me/Projects/Go/src/github.com/libp2p/go-libp2p/p2p/host/basic/basic_host.go:174 +0x3e
github.com/me/go-libp2p-swarm.(*Network).SetConnHandler.func1(0xc42014a000)
/Users/me/Projects/Go/src/github.com/libp2p/go-libp2p-swarm/swarm_net.go:160 +0x3b
created by github.com/libp2p/go-libp2p-swarm.(*Swarm).SetConnHandler.func2
/Users/me/Projects/Go/src/github.com/libp2p/go-libp2p-swarm/swarm.go:260 +0x67

@FRANKzsx
Copy link

FRANKzsx commented Jan 17, 2018

@masonforest
It seems like ehco/main.makeBasicHost func not put mux.Transport as config parameter before build Host.

msmux "github.com/whyrusleeping/go-smux-multistream"
yamux "github.com/whyrusleeping/go-smux-yamux"
tpt := msmux.NewBlankTransport()
tpt.AddTransport("/echo/1.0.0", yamux.DefaultTransport)
opts := []libp2p.Option{
libp2p.ListenAddrStrings(fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", listenPort)),
libp2p.Identity(priv),
libp2p.Muxer(tpt),
}

These code maybe helpful. At least I succeeded.

@dmbreaker
Copy link

dmbreaker commented Jan 18, 2018

There is even simpler fix:

opts := []libp2p.Option{
libp2p.ListenAddrStrings(fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", listenPort)),
libp2p.Identity(priv),
libp2p.Muxer(libp2p.DefaultMuxer()), // <<
}

@FRANKzsx
Copy link

However ,the DefaultMuxer didn't include /echo/1.0.0 protocol which will be used in NewStream().
If use DefaultMuxer(), you must change protocol in NewStream()

@dmbreaker
Copy link

Strange, why it works then?

@bronze1man
Copy link

bronze1man commented Jan 22, 2018

@FRANKzsx the package name rule is another big problem for this project.
In your code:
msmux is "github.com/whyrusleeping/go-smux-multistream"
yamux is "github.com/whyrusleeping/go-smux-yamux"

Why not just name it as "github.com/whyrusleeping/goSmuxMultistream" ,and import it as goSmuxMultistream ?

@FRANKzsx
Copy link

@bronze1man Yes,you are right. I followed the importing of project habits. But it may be better to use directly package name for example. At least, I should declare this package import. Thank you very much.

@FRANKzsx
Copy link

@dmbreaker I feel strange, too.
I try to use DefaultMuxer() but get error with:
dial attempt failed: failed to add conn to ps.Swarm: protocol not supported main.go:100.

@nuxibyte
Copy link
Contributor

@FRANKzsx I was having the same error when creating an even more basic example for myself by splitting out the listen code from the dial code.

Adding the default mux line worked for me.

I can share the code if you want.

@Stebalien
Copy link
Member

I believe this has now been fixed. @nuxibyte, @FRANKzsx, @masonforest could you pull and try again?

@masonforest
Copy link
Author

Yep! It works! 👍 Thanks :)

@jvsteiner
Copy link
Contributor

This issuse still crops up when using bhost.NewHost() however the fix must be different, because the muxer option in bhost.HostOpts is a different type (*msmux.MultistreamMuxer) than what is returned by libp2p.DefaultMuxer() - that function returns a streammux.Transport

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants