Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Beyond Protocol
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Beyond AKA
Beyond Protocol
Commits
ae8ea389
Commit
ae8ea389
authored
2 years ago
by
Nicolas Pope
Browse files
Options
Downloads
Patches
Plain Diff
#61
Peer and universe shutdown fixes
parent
38f230f4
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/peer.cpp
+4
-2
4 additions, 2 deletions
src/peer.cpp
src/universe.cpp
+22
-12
22 additions, 12 deletions
src/universe.cpp
src/universe.hpp
+1
-0
1 addition, 0 deletions
src/universe.hpp
test/net_integration.cpp
+19
-0
19 additions, 0 deletions
test/net_integration.cpp
with
46 additions
and
14 deletions
src/peer.cpp
+
4
−
2
View file @
ae8ea389
...
@@ -568,9 +568,11 @@ Peer::~Peer() {
...
@@ -568,9 +568,11 @@ Peer::~Peer() {
}
}
// Prevent deletion if there are any jobs remaining
// Prevent deletion if there are any jobs remaining
if
(
job_count_
>
0
&&
ftl
::
pool
.
size
()
>
0
)
{
int
count
=
10
;
while
(
job_count_
>
0
&&
ftl
::
pool
.
size
()
>
0
&&
count
--
>
0
)
{
DLOG
(
1
)
<<
"Waiting on peer jobs... "
<<
job_count_
;
DLOG
(
1
)
<<
"Waiting on peer jobs... "
<<
job_count_
;
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
2
));
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
2
));
if
(
job_count_
>
0
)
LOG
(
FATAL
)
<<
"Peer jobs not terminated"
;
}
}
if
(
job_count_
>
0
)
LOG
(
FATAL
)
<<
"Peer jobs not terminated"
;
}
}
This diff is collapsed.
Click to expand it.
src/universe.cpp
+
22
−
12
View file @
ae8ea389
...
@@ -192,11 +192,17 @@ void Universe::shutdown() {
...
@@ -192,11 +192,17 @@ void Universe::shutdown() {
active_
=
false
;
active_
=
false
;
thread_
.
join
();
thread_
.
join
();
// FIXME: This shouldn't be needed
_cleanupPeers
();
if
(
peer_instances_
>
0
&&
ftl
::
pool
.
size
()
>
0
)
{
while
(
garbage_
.
size
()
>
0
)
{
DLOG
(
WARNING
)
<<
"Waiting on peer destruction... "
<<
peer_instances_
;
_garbage
();
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
2
));
}
// Try 10 times to delete the peers
// Note: other threads may still be using the peer object
int
count
=
10
;
while
(
peer_instances_
>
0
&&
count
--
>
0
)
{
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
2
));
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
2
));
if
(
peer_instances_
>
0
)
LOG
(
FATAL
)
<<
"Peers not destroyed"
;
}
}
}
}
...
@@ -467,6 +473,11 @@ void Universe::_periodic() {
...
@@ -467,6 +473,11 @@ void Universe::_periodic() {
// Garbage peers may not be needed any more
// Garbage peers may not be needed any more
if
(
garbage_
.
size
()
>
0
)
{
if
(
garbage_
.
size
()
>
0
)
{
_garbage
();
}
}
void
Universe
::
_garbage
()
{
UNIQUE_LOCK
(
net_mutex_
,
lk
);
UNIQUE_LOCK
(
net_mutex_
,
lk
);
// Only do garbage if processing is idle.
// Only do garbage if processing is idle.
if
(
ftl
::
pool
.
n_idle
()
==
ftl
::
pool
.
size
())
{
if
(
ftl
::
pool
.
n_idle
()
==
ftl
::
pool
.
size
())
{
...
@@ -477,7 +488,6 @@ void Universe::_periodic() {
...
@@ -477,7 +488,6 @@ void Universe::_periodic() {
}
}
}
}
}
}
}
void
Universe
::
__start
(
Universe
*
u
)
{
void
Universe
::
__start
(
Universe
*
u
)
{
#ifndef WIN32
#ifndef WIN32
...
...
This diff is collapsed.
Click to expand it.
src/universe.hpp
+
1
−
0
View file @
ae8ea389
...
@@ -191,6 +191,7 @@ class Universe {
...
@@ -191,6 +191,7 @@ class Universe {
void
_notifyDisconnect
(
ftl
::
net
::
Peer
*
);
void
_notifyDisconnect
(
ftl
::
net
::
Peer
*
);
void
_notifyError
(
ftl
::
net
::
Peer
*
,
ftl
::
protocol
::
Error
,
const
std
::
string
&
);
void
_notifyError
(
ftl
::
net
::
Peer
*
,
ftl
::
protocol
::
Error
,
const
std
::
string
&
);
void
_periodic
();
void
_periodic
();
void
_garbage
();
ftl
::
net
::
PeerPtr
_findPeer
(
const
ftl
::
net
::
Peer
*
p
);
ftl
::
net
::
PeerPtr
_findPeer
(
const
ftl
::
net
::
Peer
*
p
);
void
_removePeer
(
PeerPtr
&
p
);
void
_removePeer
(
PeerPtr
&
p
);
void
_insertPeer
(
const
ftl
::
net
::
PeerPtr
&
ptr
);
void
_insertPeer
(
const
ftl
::
net
::
PeerPtr
&
ptr
);
...
...
This diff is collapsed.
Click to expand it.
test/net_integration.cpp
+
19
−
0
View file @
ae8ea389
...
@@ -24,6 +24,25 @@ static bool try_for(int count, const std::function<bool()> &f) {
...
@@ -24,6 +24,25 @@ static bool try_for(int count, const std::function<bool()> &f) {
// --- Tests -------------------------------------------------------------------
// --- Tests -------------------------------------------------------------------
TEST_CASE
(
"Garbage bug"
,
"[net]"
)
{
auto
self
=
ftl
::
createDummySelf
();
self
->
listen
(
ftl
::
URI
(
"tcp://localhost:0"
));
auto
uri
=
"tcp://127.0.0.1:"
+
std
::
to_string
(
self
->
getListeningURIs
().
front
().
getPort
());
LOG
(
INFO
)
<<
uri
;
auto
p
=
ftl
::
connectNode
(
uri
);
REQUIRE
(
p
);
REQUIRE
(
p
->
waitConnection
(
5
)
);
REQUIRE
(
self
->
waitConnections
(
5
)
==
1
);
REQUIRE
(
ftl
::
getSelf
()
->
numberOfNodes
()
==
1
);
p
.
reset
();
ftl
::
protocol
::
reset
();
}
TEST_CASE
(
"Listen and Connect"
,
"[net]"
)
{
TEST_CASE
(
"Listen and Connect"
,
"[net]"
)
{
auto
self
=
ftl
::
createDummySelf
();
auto
self
=
ftl
::
createDummySelf
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment