holepunch: s.holePuncher is nil on close #1448
Labels
help wanted
Seeking public contribution on this issue
kind/bug
A bug in existing code (including security flaws)
Sys info
go-libp2p@v0.19.0
Issue
When closing holepuncher it panics when it hadn't been created yet. Let me explain:
When holepuncher is closed, then the s.holePuncher is closed no matter what:
go-libp2p/p2p/protocol/holepunch/svc.go
Lines 148 to 156 in 5151d4b
It's worth noting that s.holePuncher is a pointer that is
nil
by default:go-libp2p/p2p/protocol/holepunch/svc.go
Lines 44 to 57 in 5151d4b
And that s.holePuncher is only initialized in s.watchForPublicAddr func when some conditions are met:
go-libp2p/p2p/protocol/holepunch/svc.go
Line 141 in 5151d4b
This is a problem because if the s.holePuncher isn't initalized and we would call s.Close then s.holePuncher.Close() would panic (because it is not designed to be "zero value" closed).
Solution:
The simplest solution is to introduce a nil check when closing holepuncher, it will check if s.holePuncher is nil or not.
The text was updated successfully, but these errors were encountered: