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

"panic: runtime error: invalid memory address or nil pointer dereference" in p2p/host/autorelay/relay_finder.go:209 if EnableAutoRelay() #1852

Closed
Tracked by #1766
alx696 opened this issue Nov 2, 2022 · 17 comments · Fixed by #1863
Assignees
Labels
kind/bug A bug in existing code (including security flaws)

Comments

@alx696
Copy link

alx696 commented Nov 2, 2022

After update to v0.23.2, an error will occur:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xc77f31]

goroutine 8824 [running]:
github.com/libp2p/go-libp2p/p2p/host/autorelay.(*relayFinder).findNodes(0xc00010ed00, {0x146f198?, 0xc002d3f940})
        /home/m/go/pkg/mod/github.com/libp2p/go-libp2p@v0.23.2/p2p/host/autorelay/relay_finder.go:209 +0x51
github.com/libp2p/go-libp2p/p2p/host/autorelay.(*relayFinder).background.func2()
        /home/m/go/pkg/mod/github.com/libp2p/go-libp2p@v0.23.2/p2p/host/autorelay/relay_finder.go:112 +0x66
created by github.com/libp2p/go-libp2p/p2p/host/autorelay.(*relayFinder).background
        /home/m/go/pkg/mod/github.com/libp2p/go-libp2p@v0.23.2/p2p/host/autorelay/relay_finder.go:110 +0x192

    at ChildProcess.exithandler (node:child_process:407:12)
    at ChildProcess.emit (node:events:527:28)
    at maybeClose (node:internal/child_process:1092:16)
    at Socket.<anonymous> (node:internal/child_process:451:11)
    at Socket.emit (node:events:527:28)
    at Pipe.<anonymous> (node:net:709:12)

If comment out libp2p.EnableAutoRelay() , no errors.

libp2p.New(
		// Use the keypair we generated
		libp2p.Identity(*myKey),
		// Multiple listen addresses
		libp2p.ListenAddrStrings(
			fmt.Sprint("/ip4/0.0.0.0/tcp/", port),          // regular tcp connections
			fmt.Sprint("/ip4/0.0.0.0/udp/", port, "/quic"), // a UDP endpoint for the QUIC transport
			fmt.Sprint("/ip6/::/udp/", port, "/quic"),      // a UDP endpoint for the QUIC transport
		),
		// support TLS connections
		libp2p.Security(libp2p_tls.ID, libp2p_tls.New),
		// support noise connections
		libp2p.Security(noise.ID, noise.New),
		// support any other default transports (TCP)
		libp2p.DefaultTransports,
		// Let's prevent our peer from having too many
		// connections by attaching a connection manager.
		libp2p.ConnectionManager(connmgr),
		// Attempt to open ports using uPNP for NATed hosts.
		libp2p.NATPortMap(),
		// Let this host use the DHT to find other hosts
		libp2p.Routing(func(h host.Host) (routing.PeerRouting, error) {
			var e error
			globalDHT, e = libp2p_dht.New(globalContext, h)
			return globalDHT, e
		}),

		// Can not enable: panic: runtime error: invalid memory address or nil pointer dereference
		// // Let this host use relays and advertise itself on relays if
		// // it finds it is behind NAT. Use libp2p.Relay(options...) to
		// // enable active relays and more.
		// libp2p.EnableAutoRelay(),

		// If you want to help other peers to figure out if they are behind
		// NATs, you can launch the server-side of AutoNAT too (AutoRelay
		// already runs the client)
		//
		// This service is highly rate-limited and should not cause any
		// performance issues.
		libp2p.EnableNATService(),
	)
Version Information
go-open-p2p
cloud.google.com/go v0.65.0
cloud.google.com/go/bigquery v1.8.0
cloud.google.com/go/datastore v1.1.0
cloud.google.com/go/pubsub v1.3.1
cloud.google.com/go/storage v1.10.0
dmitri.shuralyov.com/app/changes v0.0.0-20180602232624-0a106ad413e3
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9
dmitri.shuralyov.com/html/belt v0.0.0-20180602232347-f7d459c86be0
dmitri.shuralyov.com/service/change v0.0.0-20181023043359-a85b471d5412
dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999
github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96
github.com/BurntSushi/toml v0.3.1
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802
github.com/OneOfOne/xxhash v1.2.2
github.com/aead/siphash v1.0.1
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d
github.com/andybalholm/brotli v1.0.4
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6
github.com/benbjohnson/clock v1.3.0
github.com/beorn7/perks v1.0.1
github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625
github.com/btcsuite/btcd v0.20.1-beta
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd
github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd
github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792
github.com/btcsuite/winsvc v1.0.0
github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23
github.com/census-instrumentation/opencensus-proto v0.2.1
github.com/cespare/xxhash v1.1.0
github.com/cespare/xxhash/v2 v2.1.2
github.com/cheekybits/genny v1.0.0
github.com/chzyer/logex v1.1.10
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1
github.com/cilium/ebpf v0.4.0
github.com/client9/misspell v0.3.4
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f
github.com/containerd/cgroups v1.0.4
github.com/coreos/etcd v3.3.10+incompatible
github.com/coreos/go-etcd v2.0.0+incompatible
github.com/coreos/go-semver v0.3.0
github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d
github.com/coreos/go-systemd/v22 v22.4.0
github.com/cpuguy83/go-md2man v1.0.10
github.com/cpuguy83/go-md2man/v2 v2.0.0
github.com/davecgh/go-spew v1.1.1
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c
github.com/decred/dcrd/crypto/blake256 v1.0.0
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0
github.com/dgraph-io/badger v1.6.2
github.com/dgraph-io/ristretto v0.0.2
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2
github.com/docker/go-units v0.5.0
github.com/dustin/go-humanize v1.0.0
github.com/elastic/gosigar v0.14.2
github.com/envoyproxy/go-control-plane v0.9.4
github.com/envoyproxy/protoc-gen-validate v0.1.0
github.com/fasthttp/websocket v1.5.0
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568
github.com/flynn/noise v1.0.0
github.com/francoispqt/gojay v1.2.13
github.com/frankban/quicktest v1.11.3
github.com/fsnotify/fsnotify v1.5.4
github.com/ghodss/yaml v1.0.0
github.com/gliderlabs/ssh v0.1.1
github.com/go-errors/errors v1.0.1
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4
github.com/go-kit/kit v0.9.0
github.com/go-kit/log v0.2.0
github.com/go-logfmt/logfmt v0.5.1
github.com/go-logr/logr v1.2.3
github.com/go-logr/stdr v1.2.2
github.com/go-stack/stack v1.8.0
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0
github.com/godbus/dbus/v5 v5.1.0
github.com/gogo/protobuf v1.3.2
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e
github.com/golang/lint v0.0.0-20180702182130-06c8688daad7
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.2
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db
github.com/google/btree v1.0.0
github.com/google/go-cmp v0.5.8
github.com/google/go-github v17.0.0+incompatible
github.com/google/go-querystring v1.0.0
github.com/google/gofuzz v1.0.0
github.com/google/gopacket v1.1.19
github.com/google/martian v2.1.0+incompatible
github.com/google/martian/v3 v3.0.0
github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99
github.com/google/renameio v0.1.0
github.com/google/uuid v1.3.0
github.com/googleapis/gax-go v2.0.0+incompatible
github.com/googleapis/gax-go/v2 v2.0.5
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1
github.com/gorilla/websocket v1.5.0
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7
github.com/grpc-ecosystem/grpc-gateway v1.5.0
github.com/hashicorp/errwrap v1.0.0
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/golang-lru v0.5.4
github.com/hashicorp/hcl v1.0.0
github.com/hpcloud/tail v1.0.0
github.com/huin/goupnp v1.0.3
github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6
github.com/inconshreveable/mousetrap v1.0.0
github.com/ipfs/go-cid v0.3.2
github.com/ipfs/go-datastore v0.6.0
github.com/ipfs/go-detect-race v0.0.1
github.com/ipfs/go-ds-badger v0.3.0
github.com/ipfs/go-ds-leveldb v0.5.0
github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8
github.com/ipfs/go-ipfs-util v0.0.2
github.com/ipfs/go-ipns v0.2.0
github.com/ipfs/go-log v1.0.5
github.com/ipfs/go-log/v2 v2.5.1
github.com/ipld/go-ipld-prime v0.9.0
github.com/jackpal/go-nat-pmp v1.0.2
github.com/jbenet/go-cienv v0.1.0
github.com/jbenet/go-temp-err-catcher v0.1.0
github.com/jbenet/goprocess v0.1.4
github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89
github.com/jpillora/backoff v1.0.0
github.com/jrick/logrotate v1.0.0
github.com/json-iterator/go v1.1.12
github.com/jstemmer/go-junit-report v0.9.1
github.com/jtolds/gls v4.20.0+incompatible
github.com/julienschmidt/httprouter v1.3.0
github.com/kisielk/errcheck v1.5.0
github.com/kisielk/gotool v1.0.0
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23
github.com/klauspost/compress v1.15.10
github.com/klauspost/cpuid/v2 v2.1.1
github.com/konsorten/go-windows-terminal-sequences v1.0.3
github.com/koron/go-ssdp v0.0.3
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515
github.com/kr/pretty v0.2.1
github.com/kr/pty v1.1.3
github.com/kr/text v0.1.0
github.com/libp2p/go-buffer-pool v0.1.0
github.com/libp2p/go-cidranger v1.1.0
github.com/libp2p/go-flow-metrics v0.1.0
github.com/libp2p/go-libp2p v0.23.2
github.com/libp2p/go-libp2p-asn-util v0.2.0
github.com/libp2p/go-libp2p-core v0.20.0
github.com/libp2p/go-libp2p-kad-dht v0.18.0
github.com/libp2p/go-libp2p-kbucket v0.4.7
github.com/libp2p/go-libp2p-peerstore v0.8.0
github.com/libp2p/go-libp2p-record v0.2.0
github.com/libp2p/go-libp2p-routing-helpers v0.2.3
github.com/libp2p/go-libp2p-testing v0.12.0
github.com/libp2p/go-libp2p-xor v0.1.0
github.com/libp2p/go-maddr-filter v0.1.0
github.com/libp2p/go-mplex v0.7.0
github.com/libp2p/go-msgio v0.2.0
github.com/libp2p/go-nat v0.1.0
github.com/libp2p/go-netroute v0.2.0
github.com/libp2p/go-openssl v0.1.0
github.com/libp2p/go-reuseport v0.2.0
github.com/libp2p/go-sockaddr v0.0.2
github.com/libp2p/go-yamux/v3 v3.1.2
github.com/libp2p/go-yamux/v4 v4.0.0
github.com/libp2p/zeroconf/v2 v2.2.0
github.com/lucas-clemente/quic-go v0.29.1
github.com/lunixbochs/vtclean v1.0.0
github.com/magiconair/properties v1.8.0
github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe
github.com/makiuchi-d/gozxing v0.1.1
github.com/marten-seemann/qpack v0.2.1
github.com/marten-seemann/qtls-go1-16 v0.1.5
github.com/marten-seemann/qtls-go1-17 v0.1.2
github.com/marten-seemann/qtls-go1-18 v0.1.2
github.com/marten-seemann/qtls-go1-19 v0.1.0
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd
github.com/marten-seemann/webtransport-go v0.1.1
github.com/mattn/go-colorable v0.1.1
github.com/mattn/go-isatty v0.0.16
github.com/mattn/go-pointer v0.0.1
github.com/matttproud/golang_protobuf_extensions v1.0.1
github.com/microcosm-cc/bluemonday v1.0.1
github.com/miekg/dns v1.1.50
github.com/mikioh/tcp v0.0.0-20190314235350-803a9b46060c
github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b
github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1
github.com/minio/sha256-simd v1.0.0
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/mapstructure v1.1.2
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
github.com/modern-go/reflect2 v1.0.2
github.com/mr-tron/base58 v1.2.0
github.com/multiformats/go-base32 v0.1.0
github.com/multiformats/go-base36 v0.1.0
github.com/multiformats/go-multiaddr v0.7.0
github.com/multiformats/go-multiaddr-dns v0.3.1
github.com/multiformats/go-multiaddr-fmt v0.1.0
github.com/multiformats/go-multiaddr-net v0.2.0
github.com/multiformats/go-multibase v0.1.1
github.com/multiformats/go-multicodec v0.6.0
github.com/multiformats/go-multihash v0.2.1
github.com/multiformats/go-multistream v0.3.3
github.com/multiformats/go-varint v0.0.6
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f
github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86
github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab
github.com/nxadm/tail v1.4.8
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.13.0
github.com/opencontainers/runtime-spec v1.0.2
github.com/opentracing/opentracing-go v1.2.0
github.com/openzipkin/zipkin-go v0.1.1
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58
github.com/pelletier/go-toml v1.2.0
github.com/pkg/errors v0.9.1
github.com/pmezard/go-difflib v1.0.0
github.com/polydawn/refmt v0.0.0-20190807091052-3d65705ee9f1
github.com/prometheus/client_golang v1.13.0
github.com/prometheus/client_model v0.2.0
github.com/prometheus/common v0.37.0
github.com/prometheus/procfs v0.8.0
github.com/raulk/go-watchdog v1.3.0
github.com/rogpeppe/go-internal v1.3.0
github.com/russross/blackfriday v1.5.2
github.com/russross/blackfriday/v2 v2.0.1
github.com/savsgio/gotils v0.0.0-20211223103454-d0aaa54c5899
github.com/sergi/go-diff v1.0.0
github.com/shurcooL/component v0.0.0-20170202220835-f88ec8f54cc4
github.com/shurcooL/events v0.0.0-20181021180414-410e4ca65f48
github.com/shurcooL/github_flavored_markdown v0.0.0-20181002035957-2122de532470
github.com/shurcooL/go v0.0.0-20180423040247-9e1955d9fb6e
github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041
github.com/shurcooL/gofontwoff v0.0.0-20180329035133-29b52fc0a18d
github.com/shurcooL/gopherjslib v0.0.0-20160914041154-feb6d3990c2c
github.com/shurcooL/highlight_diff v0.0.0-20170515013008-09bb4053de1b
github.com/shurcooL/highlight_go v0.0.0-20181028180052-98c3abbbae20
github.com/shurcooL/home v0.0.0-20181020052607-80b7ffcb30f9
github.com/shurcooL/htmlg v0.0.0-20170918183704-d01228ac9e50
github.com/shurcooL/httperror v0.0.0-20170206035902-86b7830d14cc
github.com/shurcooL/httpfs v0.0.0-20171119174359-809beceb2371
github.com/shurcooL/httpgzip v0.0.0-20180522190206-b1c53ac65af9
github.com/shurcooL/issues v0.0.0-20181008053335-6292fdc1e191
github.com/shurcooL/issuesapp v0.0.0-20180602232740-048589ce2241
github.com/shurcooL/notifications v0.0.0-20181007000457-627ab5aea122
github.com/shurcooL/octicon v0.0.0-20181028054416-fa4f57f9efb2
github.com/shurcooL/reactions v0.0.0-20181006231557-f2e0b4ca5b82
github.com/shurcooL/sanitized_anchor_name v1.0.0
github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537
github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133
github.com/sirupsen/logrus v1.8.1
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d
github.com/smartystreets/goconvey v1.6.4
github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572
github.com/spaolacci/murmur3 v1.1.0
github.com/spf13/afero v1.1.2
github.com/spf13/cast v1.3.0
github.com/spf13/cobra v0.0.5
github.com/spf13/jwalterweatherman v1.0.0
github.com/spf13/pflag v1.0.3
github.com/spf13/viper v1.3.2
github.com/stretchr/objx v0.1.1
github.com/stretchr/testify v1.8.0
github.com/syndtr/goleveldb v1.0.0
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8
github.com/urfave/cli v1.22.2
github.com/valyala/bytebufferpool v1.0.0
github.com/valyala/fasthttp v1.41.0
github.com/valyala/tcplisten v1.0.0
github.com/viant/assertly v0.4.8
github.com/viant/toolbox v0.24.0
github.com/warpfork/go-wish v0.0.0-20200122115046-b9ea61034e4a
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1
github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77
github.com/yuin/goldmark v1.4.13
go.opencensus.io v0.23.0
go.opentelemetry.io/otel v1.7.0
go.opentelemetry.io/otel/trace v1.7.0
go.uber.org/atomic v1.10.0
go.uber.org/goleak v1.1.12
go.uber.org/multierr v1.8.0
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee
go.uber.org/zap v1.23.0
go4.org v0.0.0-20180809161055-417644f6feb5
golang.org/x/build v0.0.0-20190111050920-041ab4dc3f9d
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e
golang.org/x/exp v0.0.0-20220916125017-b168a2c6b86b
golang.org/x/image v0.0.0-20190802002840-cff245a6509b
golang.org/x/lint v0.0.0-20200302205851-738671d3881b
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4
golang.org/x/net v0.0.0-20220920183852-bf014ff85ad5
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b
golang.org/x/perf v0.0.0-20180704124530-6e6d33e29852
golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
golang.org/x/text v0.3.7
golang.org/x/time v0.0.0-20191024005414-555d28b269f0
golang.org/x/tools v0.1.12
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
google.golang.org/api v0.30.0
google.golang.org/appengine v1.6.6
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987
google.golang.org/grpc v1.33.2
google.golang.org/protobuf v1.28.1
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
gopkg.in/errgo.v2 v2.1.0
gopkg.in/fsnotify.v1 v1.4.7
gopkg.in/inf.v0 v0.9.1
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
grpc.go4.org v0.0.0-20170609214715-11d0a25b4919
honnef.co/go/tools v0.0.1-2020.1.4
lukechampine.com/blake3 v1.1.7
rsc.io/binaryregexp v0.2.0
rsc.io/quote/v3 v3.1.0
rsc.io/sampler v1.3.0
sourcegraph.com/sourcegraph/go-diff v0.5.0
sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4
@alx696 alx696 changed the title "panic: runtime error: invalid memory address or nil pointer dereference" in p2p/host/autorelay/relay_finder.go:209 "panic: runtime error: invalid memory address or nil pointer dereference" in p2p/host/autorelay/relay_finder.go:209 if EnableAutoRelay() Nov 2, 2022
@marten-seemann
Copy link
Contributor

Have you changed anything in the code? This is the standard code path, which should be covered quite well by our tests.

When does the crash occur? Is it directly after you start the node, or does it take some time?

@alx696
Copy link
Author

alx696 commented Nov 2, 2022

@marten-seemann Code not changed. Error occurs after the node starts up for a while.

alx696/go-open-p2p@e87dff4

This modification upgrades Go and libp2p, op/op.go adjusted according to the new api, other files just formated.

@marten-seemann
Copy link
Contributor

@alx696 Can you please turn on autorelay debug logging? GOLOG_LOG_LEVEL="autorelay=debug" go run ... and post the output here?

@marten-seemann marten-seemann added the need/author-input Needs input from the original author label Nov 5, 2022
@alx696
Copy link
Author

alx696 commented Nov 6, 2022

@marten-seemann I am using go-open-p2p as embedded. I do not know how to set environment variable that time.

The error occurs when calling the method .

[2022-11-06 12:02:29.333] [debug] 可用端口: 29839
[2022-11-06 12:02:29.338] [info]  资源路径: /home/m/learn/network-express/desktop-ne
[2022-11-06 12:02:29.338] [info]  文件夹路径: /home/m/lilu-ne
[2022-11-06 12:02:29.338] [info]  http端口: 29839
[2022-11-06 12:02:29.343] [debug] 后台服务进程 34692
[2022-11-06 12:08:36.117] [info]  退出应用
[2022-11-06 12:08:36.117] [info]  结束进程
[2022-11-06 12:15:10.982] [debug] 可用端口: 31125
[2022-11-06 12:15:10.987] [info]  资源路径: /home/m/learn/network-express/desktop-ne
[2022-11-06 12:15:10.987] [info]  文件夹路径: /home/m/lilu-ne
[2022-11-06 12:15:10.988] [info]  http端口: 31125
[2022-11-06 12:15:10.993] [debug] 后台服务进程 39194
[2022-11-06 12:19:40.551] [info]  退出应用
[2022-11-06 12:19:40.552] [info]  结束进程
[2022-11-06 12:19:45.977] [debug] 可用端口: 5213
[2022-11-06 12:19:45.981] [info]  资源路径: /home/m/learn/network-express/desktop-ne
[2022-11-06 12:19:45.982] [info]  文件夹路径: /home/m/lilu-ne
[2022-11-06 12:19:45.982] [info]  http端口: 5213
[2022-11-06 12:19:45.988] [debug] 后台服务进程 39704
[2022-11-06 12:21:16.729] [error] Error: Command failed: /home/m/learn/network-express/desktop-ne/op-linux --private=/home/m/lilu-ne/private --public=/home/m/lilu-ne/public --http=5213
2022/11/06 12:19:45 启动开放点对点
2022/11/06 12:19:45 私有文件夹 /home/m/lilu-ne/private
2022/11/06 12:19:45 公共文件夹 /home/m/lilu-ne/public
2022/11/06 12:19:45 开始启动HTTP服务: 5213
2022/11/06 12:19:46 通过dnsaddr得到引导地址 [/dnsaddr/am6.bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb /dnsaddr/ams-rust.bootstrap.libp2p.io/p2p/12D3KooWEZXjE41uU4EL2gpkAQeDXYok6wghN7wwNVPF5bwkaNfS /dnsaddr/ny5.bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa /dnsaddr/sg1.bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt /dnsaddr/sv15.bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN /dnsaddr/sv16.bootstrap.libp2p.io/p2p/QmZa1sAxajnQjVM8WjWXoMbmPd7NsWhfKsPkErzpm9wGkp]
2022/11/06 12:19:46 通过lilu.red得到引导地址 [/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ]
2022/11/06 12:19:46 初始化交换
2022/11/06 12:19:46 开放点对点已经启动 12D3KooWPkyhax3pTe2uBn3TXCiQ3JriAGQGoSWEiZved18rv4Ge [/ip4/192.168.1.3/tcp/20245 /ip4/127.0.0.1/tcp/20245 /ip4/192.168.1.3/udp/53659/quic /ip4/127.0.0.1/udp/53659/quic /ip6/2408:824e:1530:e2b0:5c44:6b4e:4ba2:26e0/udp/14207/quic /ip6/::1/udp/14207/quic]
2022/11/06 12:19:46 回调启动 12D3KooWPkyhax3pTe2uBn3TXCiQ3JriAGQGoSWEiZved18rv4Ge ["/ip4/192.168.1.3/tcp/20245","/ip4/127.0.0.1/tcp/20245","/ip4/192.168.1.3/udp/53659/quic","/ip4/127.0.0.1/udp/53659/quic","/ip6/2408:824e:1530:e2b0:5c44:6b4e:4ba2:26e0/udp/14207/quic","/ip6/::1/udp/14207/quic"]
2022/11/06 12:19:46 启动MDNS
2022/11/06 12:19:46 启动状态
2022/11/06 12:19:46 启动连接状态
2022/11/06 12:19:46 MDNS发现节点 12D3KooWMhFqJytxaCBQMr936uvcu8ZVxf8yspPGWnECRqov5SjA
2022/11/06 12:19:46 回调MDNS发现节点 12D3KooWMhFqJytxaCBQMr936uvcu8ZVxf8yspPGWnECRqov5SjA
2022-11-06T12:19:46.307+0800	DEBUG	autorelay	autorelay/relay_finder.go:666	stopping relay finder
2022/11/06 12:19:46 连接引导成功 /dnsaddr/sv15.bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN
2022/11/06 12:19:46 连接引导成功 /dnsaddr/am6.bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb
2022/11/06 12:19:46 连接引导成功 /dnsaddr/ny5.bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa
2022/11/06 12:19:46 连接引导成功 /dnsaddr/sv16.bootstrap.libp2p.io/p2p/QmZa1sAxajnQjVM8WjWXoMbmPd7NsWhfKsPkErzpm9wGkp
2022/11/06 12:19:46 连接引导成功 /dnsaddr/sg1.bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt
2022/11/06 12:19:47 订阅请求:  网页
2022/11/06 12:19:47 设置状态检查标识数组 []
2022/11/06 12:19:48 连接引导成功 /dnsaddr/ams-rust.bootstrap.libp2p.io/p2p/12D3KooWEZXjE41uU4EL2gpkAQeDXYok6wghN7wwNVPF5bwkaNfS
2022/11/06 12:19:51 连接引导失败 /ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ failed to dial QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ:
  * [/p2p-circuit/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ] can't dial a p2p-circuit without specifying a relay: /p2p-circuit/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ
  * [/ip4/104.131.131.82/tcp/4001] dial tcp4 0.0.0.0:20245->104.131.131.82:4001: i/o timeout
2022-11-06T12:21:16.717+0800	DEBUG	autorelay	autorelay/relay_finder.go:652	starting relay finder
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xc778f1]

goroutine 24701 [running]:
github.com/libp2p/go-libp2p/p2p/host/autorelay.(*relayFinder).findNodes(0xc000118d00, {0x146eed8?, 0xc00316e900})
	/home/m/go/pkg/mod/github.com/libp2p/go-libp2p@v0.23.2/p2p/host/autorelay/relay_finder.go:209 +0x51
github.com/libp2p/go-libp2p/p2p/host/autorelay.(*relayFinder).background.func2()
	/home/m/go/pkg/mod/github.com/libp2p/go-libp2p@v0.23.2/p2p/host/autorelay/relay_finder.go:112 +0x66
created by github.com/libp2p/go-libp2p/p2p/host/autorelay.(*relayFinder).background
	/home/m/go/pkg/mod/github.com/libp2p/go-libp2p@v0.23.2/p2p/host/autorelay/relay_finder.go:110 +0x192

    at ChildProcess.exithandler (node:child_process:407:12)
    at ChildProcess.emit (node:events:527:28)
    at maybeClose (node:internal/child_process:1092:16)
    at Socket.<anonymous> (node:internal/child_process:451:11)
    at Socket.emit (node:events:527:28)
    at Pipe.<anonymous> (node:net:709:12)
[2022-11-06 12:22:03.571] [info]  退出应用
[2022-11-06 12:22:03.572] [info]  结束进程

@marten-seemann
Copy link
Contributor

@marten-seemann I am using go-open-p2p as embedded. I do not know how to set environment variable that time.

Unfortunately, we won't be able to debug this any further without the autorelay log.

You can just set the environment variable on your system:

export GOLOG_LOG_LEVEL="autorelay=debug"

Alternatively, in your code:

import logging "github.com/ipfs/go-log/v2"

func init() {
     logging.SetLogLevel("autorelay", "debug")
}

@alx696
Copy link
Author

alx696 commented Nov 6, 2022

@marten-seemann Thanks for you reply. I have try run GOLOG_LOG_LEVEL="autorelay=debug" npm test with desktop version base electron. I also add

import logging "github.com/ipfs/go-log/v2"

func init() {
     logging.SetLogLevel("autorelay", "debug")
}

to op/op.go.

It looks like there are only 2 more logs:

electron:

2022-11-06T12:19:46.307+0800	DEBUG	autorelay	autorelay/relay_finder.go:666	stopping relay finder

2022-11-06T12:21:16.717+0800	DEBUG	autorelay	autorelay/relay_finder.go:652	starting relay finder

Android:

2022-11-06 19:47:06.365 13277-13376 GoLog                   red.lilu.app.ne                      E  2022-11-06T11:47:06.358Z	DEBUG	autorelay	autorelay/relay_finder.go:666	stopping relay finder
2022-11-06 19:47:21.113 13277-13381 red.lilu.app.n          red.lilu.app.ne                      W  0xebadde09 skipped times: 0
2022-11-06 19:47:21.118 13277-0     Go                      red.lilu.app.ne                      E  panic: runtime error: invalid memory address or nil pointer dereference
2022-11-06 19:47:21.118 13277-0     Go                      red.lilu.app.ne                      E  [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7546fe59c8]
2022-11-06 19:47:21.119 13277-0     Go                      red.lilu.app.ne                      E  
2022-11-06 19:47:21.119 13277-0     Go                      red.lilu.app.ne                      E  goroutine 4593 [running]:
2022-11-06 19:47:21.119 13277-0     Go                      red.lilu.app.ne                      E  github.com/libp2p/go-libp2p/p2p/host/autorelay.(*relayFinder).findNodes(0x40002be9c0, {0x7547701658?, 0x4002b0e3c0})
2022-11-06 19:47:21.119 13277-0     Go                      red.lilu.app.ne                      E  	/tmp/gomobile-work-3313461825/pkg/mod/github.com/libp2p/go-libp2p@v0.23.2/p2p/host/autorelay/relay_finder.go:209 +0x38

Sorry for not providing useful information. Thanks very much.

@alx696 alx696 closed this as completed Nov 6, 2022
@marten-seemann marten-seemann reopened this Nov 6, 2022
@Raffy27
Copy link

Raffy27 commented Nov 6, 2022

Hi there, I am currently facing the same issue. It appears that running with the log level set to debug yields an additional line, but nothing of interest.

2022-11-06T14:19:57.407+0200    DEBUG   autorelay       autorelay/relay_finder.go:657   starting relay finder
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xc8ca16]

goroutine 2346 [running]:
github.com/libp2p/go-libp2p/p2p/host/autorelay.(*relayFinder).findNodes(0xc0001284e0, {0x13c2158?, 0xc0032b8b00})
        /home/raffy/go/pkg/mod/github.com/libp2p/go-libp2p@v0.23.2/p2p/host/autorelay/relay_finder.go:214 +0xf6
github.com/libp2p/go-libp2p/p2p/host/autorelay.(*relayFinder).background.func2()
        /home/raffy/go/pkg/mod/github.com/libp2p/go-libp2p@v0.23.2/p2p/host/autorelay/relay_finder.go:112 +0x66
created by github.com/libp2p/go-libp2p/p2p/host/autorelay.(*relayFinder).background
        /home/raffy/go/pkg/mod/github.com/libp2p/go-libp2p@v0.23.2/p2p/host/autorelay/relay_finder.go:110 +0x192
exit status 2
Setup code I used

func setupHost(ctx context.Context, cfg *P2PNetworkConfig) (host.Host, *dht.IpfsDHT, error) {
	cm, err := connmgr.NewConnManager(100, 400)
	if err != nil {
		return nil, nil, err
	}
	privKey, err := DeriveIdentity(cfg.PrivateKey)
	if err != nil {
		return nil, nil, err
	}
	zap.S().Debug("identity derived")

	// Setup libp2p host with custom options
	// We will initialize a Kademlia DHT instance in the meantime
	var kadDHT *dht.IpfsDHT
	h, err := libp2p.New(
		libp2p.Identity(privKey),
		libp2p.ListenAddrStrings(cfg.ListenAddr),
		// Security
		// Transport
		// Muxer
		libp2p.ConnectionManager(cm),
		libp2p.NATPortMap(),
		libp2p.Routing(func(h host.Host) (routing.PeerRouting, error) {
			kadDHT, err = dht.New(
				ctx, h,
				dht.Mode(dht.ModeServer),
				dht.BootstrapPeers(
					dht.GetDefaultBootstrapPeerAddrInfos()...,
				),
			)
			return kadDHT, err
		}),
		// AutoRelay
		libp2p.EnableAutoRelay(),
	)

	return h, kadDHT, err
}

The same logic used to work with previous versions of the libp2p infrastructure (see peerchat for an example).
It seems that, for some reason the peerSource function is holding nil when findPeers is called.

There was a recent discussion on the libp2p forums featuring the same error, I'll leave this here in case it is related: https://discuss.libp2p.io/t/minimal-example-for-autonat-autorelay-with-pnet/1589. Even though there has been a huge improvement in the quality of the available documentation, I could not find a minimal example with AutoRelay, which would probably help a lot in this case.

@Stebalien
Copy link
Member

Yeah, it looks like peerSource just isn't set. It looks like we either need to pass WIthStaticRelays, WithDefaultStaticRelays, or WithPeerSource.

@MarcoPolo
Copy link
Collaborator

I’m touching this code today, I can fix this.

@MarcoPolo MarcoPolo self-assigned this Nov 7, 2022
@p-shahi p-shahi added this to go-libp2p Nov 7, 2022
@p-shahi p-shahi added kind/bug A bug in existing code (including security flaws) and removed need/author-input Needs input from the original author labels Nov 7, 2022
@marten-seemann marten-seemann mentioned this issue Nov 8, 2022
34 tasks
@MarcoPolo
Copy link
Collaborator

@marten-seemann this is actually this issue I brought up in Code review: #1587 (comment).

We should at the very least panic in the constructor with a useful error. I don't think it's nice to nil pointer panic on users for not having deep knowledge with how autorelay works (it has auto in the name!). The docs around EnableAutoRelay could clarify that you must call this with at least autorelay.WithStaticRelays(...) or autorelay.WithPeerSource (I'll update).

For the time being folks can see how this is used in Kubo You'll need to pass a static list of relays or a way to get relay peers.

@marten-seemann
Copy link
Contributor

@marten-seemann this is actually this issue I brought up in Code review: #1587 (comment).

You're right. My bad.

The best way to solve this would be to have an error returned by libp2p.EnableAutoRelay. It's a bit difficult to implement, considering that we're using the options pattern here.

We could split the function into two options, one that requires a list of static relays and one that requires a peer source. Having options, some of which are required, is not a nice API pattern (and this is totally my fault, I wrote it like this).

@MarcoPolo
Copy link
Collaborator

We could split the function into two options, one that requires a list of static relays and one that requires a peer source.

I think we should do this

@hsanjuan
Copy link
Contributor

I'll make more explicit that EnableAutoRelay did not need any options originally.

The right approach would have been to rename the method so that I get a big error when I build with a new libp2p version (not a panic on initialization!!), and then I can proceed to read the documentation and release notes about why a method is gone etc.

@hsanjuan
Copy link
Contributor

hsanjuan commented Nov 14, 2022

For the time being folks can see how this is used in Kubo You'll need to pass a static list of relays or a way to get relay peers.

This is very unhelpful... are we supposed to now have an autorelayFeeder and copy-paste all that code from Kubo?

@hsanjuan
Copy link
Contributor

As a user, I want to have a private network with a variable number of peers where all of them have relay capabilities that are used automatically as needed.

I'm thinking that perhaps not just the options changed, but the semantics. How did EnableAutoRelay() work before it required any options? Did it have logic to discover peers by itself?

hsanjuan added a commit to ipfs-cluster/ipfs-cluster that referenced this issue Nov 14, 2022
Per libp2p/go-libp2p#1852, the AutoRelay subsystem
is now panicking on users. EnableAutoRelay must now be called with options,
otherwise it seems to panic for some people.

Disabling it is the best for now, given relays are enabled and a node must be
able to connect to others on bootstrap, perhaps it does not need to
re-discover new relays (every other node should be a relay).

In any case we should revisit relay support and related services in Cluster,
since semantics have changed a lot in libp2p, relayV2 is a thing,
hole-punching is a thing etc. etc.
@marten-seemann
Copy link
Contributor

@hsanjuan You’re right, we should’ve broken the API when we refactored this. Better late then never, here’s the issue to split the EnableAutoRelay option: #1866.

I'm thinking that perhaps not just the options changed, but the semantics. How did EnableAutoRelay() work before it required any options? Did it have logic to discover peers by itself?

Previously, peers announced themselves as relays to the DHT, and we’d discover them from there. This was fine with a small number of relays, but obviously doesn’t scale to a network where (almost) all public nodes are relays (as they are with relay v2).

@hsanjuan
Copy link
Contributor

Previously, peers announced themselves as relays to the DHT, and we’d discover them from there. This was fine with a small number of relays, but obviously doesn’t scale to a network where (almost) all public nodes are relays (as they are with relay v2).

Makes sense. I'm trying to think if EnableAutoRelay makes sense at all on a small network where all peers are relays though (EnableRelay() is set). Does not using EnableAutoRelay mean that peers will not attempt to use other peers as relays at all? Note that they should be connected to peers that are relays already, so they potentially know that they expose the relay protocol.

hsanjuan added a commit to ipfs-cluster/ipfs-cluster that referenced this issue Jan 27, 2023
Per libp2p/go-libp2p#1852, the AutoRelay subsystem
is now panicking on users. EnableAutoRelay must now be called with options,
otherwise it seems to panic for some people.

Disabling it is the best for now, given relays are enabled and a node must be
able to connect to others on bootstrap, perhaps it does not need to
re-discover new relays (every other node should be a relay).

In any case we should revisit relay support and related services in Cluster,
since semantics have changed a lot in libp2p, relayV2 is a thing,
hole-punching is a thing etc. etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug A bug in existing code (including security flaws)
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

7 participants