Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
11cc37e4
Unverified
Commit
11cc37e4
authored
Aug 12, 2021
by
aloknerurkar
Committed by
GitHub
Aug 12, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(libp2p): cleanup peer connection after ping is done (#2403)
parent
11d393e2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
0 deletions
+9
-0
hive.go
pkg/hive/hive.go
+4
-0
libp2p.go
pkg/p2p/libp2p/libp2p.go
+5
-0
No files found.
pkg/hive/hive.go
View file @
11cc37e4
...
...
@@ -37,6 +37,7 @@ const (
peersStreamName
=
"peers"
messageTimeout
=
1
*
time
.
Minute
// maximum allowed time for a message to be read or written.
maxBatchSize
=
30
pingTimeout
=
time
.
Second
*
5
// time to wait for ping to succeed
)
var
(
...
...
@@ -277,6 +278,9 @@ func (s *Service) checkAndAddPeers(ctx context.Context, peers pb.Peers) {
return
}
ctx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
pingTimeout
)
defer
cancel
()
// check if the underlay is usable by doing a raw ping using libp2p
if
_
,
err
=
s
.
streamer
.
Ping
(
ctx
,
multiUnderlay
);
err
!=
nil
{
s
.
metrics
.
UnreachablePeers
.
Inc
()
...
...
pkg/p2p/libp2p/libp2p.go
View file @
11cc37e4
...
...
@@ -860,6 +860,11 @@ func (s *Service) Ping(ctx context.Context, addr ma.Multiaddr) (rtt time.Duratio
// Add the address to libp2p peerstore for it to be dialable
s
.
pingDialer
.
Peerstore
()
.
AddAddrs
(
info
.
ID
,
info
.
Addrs
,
peerstore
.
TempAddrTTL
)
// Cleanup connection after ping is done
defer
func
()
{
_
=
s
.
pingDialer
.
Network
()
.
ClosePeer
(
info
.
ID
)
}()
select
{
case
<-
ctx
.
Done
()
:
return
rtt
,
ctx
.
Err
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment