Skip to content

Commit 64c8441

Browse files
authored
Fix close YamuxedConnection (#301)
* Keep alive YamuxedConnection during close * weak_from_this in adjustExpireTimer
1 parent 5aa09a2 commit 64c8441

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/muxer/yamux/yamuxed_connection.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,8 @@ namespace libp2p::connection {
533533
return;
534534
}
535535

536+
// Keep alive until method completion
537+
auto self = shared_from_this();
536538
started_ = false;
537539

538540
SL_DEBUG(log(), "closing connection, reason: {}", notify_streams_code);
@@ -712,7 +714,11 @@ namespace libp2p::connection {
712714
"scheduling expire timer to {} msec",
713715
config_.no_streams_interval.count());
714716
inactivity_handle_ = scheduler_->scheduleWithHandle(
715-
[this] { onExpireTimer(); },
717+
[weak_ptr(weak_from_this())] {
718+
if (auto self = weak_ptr.lock()) {
719+
self->onExpireTimer();
720+
}
721+
},
716722
scheduler_->now() + config_.no_streams_interval);
717723
}
718724
}

0 commit comments

Comments
 (0)