Skip to content

Commit

Permalink
fix bug of disconnect
Browse files Browse the repository at this point in the history
sometime the node can not disconnect infinite. by using
PeerConnectionInterface::signaling_state(), I can get state of link
correctly.

Signed-off-by: Yuji Ito <llamerada.jp@gmail.com>
  • Loading branch information
llamerada-jp committed Jun 30, 2023
1 parent 6151eb2 commit b4667d2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions go/seed/seed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,14 @@ func TestRelayPoll(t *testing.T) {
assert.Len(resPoll.Packets, 1)
assert.Equal(packetID, resPoll.Packets[0].Id)

// get nil if the sub process finished
// get empty result if the sub process finished
ctxPoll, cancelPoll := context.WithCancel(ctx)
go func() {
resPoll, code, err := seed.poll(ctxPoll, &proto.SeedPoll{
SessionId: sessionID2,
Online: true,
})
assert.Nil(resPoll)
assert.NotNil(resPoll)
assert.Equal(http.StatusOK, code)
assert.NoError(err)
chPoll <- resPoll
Expand Down
6 changes: 4 additions & 2 deletions src/core/node_accessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,16 @@ LinkState::Type NodeAccessor::get_link_state() const {
void NodeAccessor::disconnect_all(std::function<void()> on_after) {
cleanup_closing();
if (links.size() == 0) {
assert(nid_links.size() == 0);
on_after();
return;
}

disconnect_link(first_link);
disconnect_link(random_link);

while (nid_links.size() != 0) {
disconnect_link(nid_links.begin()->second);
for (auto& it : links) {
disconnect_link(it.first);
}

scheduler.add_task(this, std::bind(&NodeAccessor::disconnect_all, this, on_after), 500);
Expand Down Expand Up @@ -581,6 +582,7 @@ void NodeAccessor::cleanup_closing() {
closing_link = closing_links.erase(closing_link);

} else {
update_link_state(*link);
// There is a link that is not closing rarely, so disconnect it.
if (link->link_state != LinkState::CLOSING) {
link->disconnect();
Expand Down
3 changes: 3 additions & 0 deletions src/core/webrtc_link_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ LinkState::Type WebrtcLinkNative::get_new_link_state() {

if (dco_state == LinkState::CLOSING || dco_state == LinkState::OFFLINE || pco_state == LinkState::CLOSING ||
pco_state == LinkState::OFFLINE) {
if (peer_connection != nullptr && peer_connection->signaling_state() == webrtc::PeerConnectionInterface::kClosed) {
return LinkState::OFFLINE;
}
disconnect();
return LinkState::CLOSING;
}
Expand Down

0 comments on commit b4667d2

Please sign in to comment.