Skip to content

Commit c06ea53

Browse files
authored
Ensure YamuxStream is alive during doClose (#303)
1 parent 64c8441 commit c06ea53

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/muxer/yamux/yamux_stream.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ namespace libp2p::connection {
316316
}
317317

318318
void YamuxStream::doClose(std::error_code ec, bool notify_read_side) {
319+
// ensure lifetime of this object during doClose
320+
auto self = shared_from_this();
319321
if (close_reason_) {
320322
// already closed
321323
return;
@@ -343,10 +345,6 @@ namespace libp2p::connection {
343345
VoidResultHandlerFunc window_size_cb;
344346
window_size_cb.swap(window_size_cb_);
345347

346-
// now we are detached from *this* and may be killed from inside callbacks
347-
// we will call
348-
auto self = shared_from_this();
349-
350348
if (read_cb_and_res.first) {
351349
read_cb_and_res.first(read_cb_and_res.second);
352350
}

0 commit comments

Comments
 (0)