提交 8e1f2381 authored 作者: Nazar Mokrynskyi's avatar Nazar Mokrynskyi

Fix rare deadlock caused by another path of dropping subscription handlers

上级 45ac3977
...@@ -105,6 +105,8 @@ impl Inner { ...@@ -105,6 +105,8 @@ impl Inner {
self.handlers.close.call_simple(); self.handlers.close.call_simple();
let subscription_handler = self.subscription_handler.lock().take();
if close_request { if close_request {
let channel = self.channel.clone(); let channel = self.channel.clone();
let request = RtpObserverCloseRequest { let request = RtpObserverCloseRequest {
...@@ -113,7 +115,6 @@ impl Inner { ...@@ -113,7 +115,6 @@ impl Inner {
rtp_observer_id: self.id, rtp_observer_id: self.id,
}, },
}; };
let subscription_handler = self.subscription_handler.lock().take();
self.executor self.executor
.spawn(async move { .spawn(async move {
...@@ -126,6 +127,14 @@ impl Inner { ...@@ -126,6 +127,14 @@ impl Inner {
drop(subscription_handler); drop(subscription_handler);
}) })
.detach(); .detach();
} else {
self.executor
.spawn(async move {
// Drop from a different thread to avoid deadlock with recursive dropping
// from within another subscription drop.
drop(subscription_handler);
})
.detach();
} }
} }
} }
......
...@@ -116,6 +116,8 @@ impl Inner { ...@@ -116,6 +116,8 @@ impl Inner {
self.handlers.close.call_simple(); self.handlers.close.call_simple();
let subscription_handler = self.subscription_handler.lock().take();
if close_request { if close_request {
let channel = self.channel.clone(); let channel = self.channel.clone();
let request = RtpObserverCloseRequest { let request = RtpObserverCloseRequest {
...@@ -124,7 +126,6 @@ impl Inner { ...@@ -124,7 +126,6 @@ impl Inner {
rtp_observer_id: self.id, rtp_observer_id: self.id,
}, },
}; };
let subscription_handler = self.subscription_handler.lock().take();
self.executor self.executor
.spawn(async move { .spawn(async move {
...@@ -137,6 +138,14 @@ impl Inner { ...@@ -137,6 +138,14 @@ impl Inner {
drop(subscription_handler); drop(subscription_handler);
}) })
.detach(); .detach();
} else {
self.executor
.spawn(async move {
// Drop from a different thread to avoid deadlock with recursive dropping
// from within another subscription drop.
drop(subscription_handler);
})
.detach();
} }
} }
} }
......
...@@ -397,6 +397,8 @@ impl Inner { ...@@ -397,6 +397,8 @@ impl Inner {
self.handlers.close.call_simple(); self.handlers.close.call_simple();
let subscription_handlers: Vec<_> = mem::take(&mut self.subscription_handlers.lock());
if close_request { if close_request {
let channel = self.channel.clone(); let channel = self.channel.clone();
let request = ConsumerCloseRequest { let request = ConsumerCloseRequest {
...@@ -407,8 +409,6 @@ impl Inner { ...@@ -407,8 +409,6 @@ impl Inner {
producer_id: self.producer_id, producer_id: self.producer_id,
}, },
}; };
let subscription_handlers: Vec<_> =
mem::take(&mut self.subscription_handlers.lock());
let weak_producer = self.weak_producer.clone(); let weak_producer = self.weak_producer.clone();
self.executor self.executor
...@@ -417,11 +417,19 @@ impl Inner { ...@@ -417,11 +417,19 @@ impl Inner {
if let Err(error) = channel.request(request).await { if let Err(error) = channel.request(request).await {
error!("consumer closing failed on drop: {}", error); error!("consumer closing failed on drop: {}", error);
} }
// Drop from a different thread to avoid deadlock with recursive dropping
// from within another subscription drop.
drop(subscription_handlers);
} }
// Drop from a different thread to avoid deadlock with recursive dropping
// from within another subscription drop.
drop(subscription_handlers);
})
.detach();
} else {
self.executor
.spawn(async move {
// Drop from a different thread to avoid deadlock with recursive dropping
// from within another subscription drop.
drop(subscription_handlers);
}) })
.detach(); .detach();
} }
......
...@@ -227,6 +227,8 @@ impl Inner { ...@@ -227,6 +227,8 @@ impl Inner {
self.handlers.close.call_simple(); self.handlers.close.call_simple();
let subscription_handlers: Vec<_> = mem::take(&mut self.subscription_handlers.lock());
if close_request { if close_request {
let channel = self.channel.clone(); let channel = self.channel.clone();
let request = DataConsumerCloseRequest { let request = DataConsumerCloseRequest {
...@@ -237,8 +239,6 @@ impl Inner { ...@@ -237,8 +239,6 @@ impl Inner {
data_producer_id: self.data_producer_id, data_producer_id: self.data_producer_id,
}, },
}; };
let subscription_handlers: Vec<_> =
mem::take(&mut self.subscription_handlers.lock());
let weak_data_producer = self.weak_data_producer.clone(); let weak_data_producer = self.weak_data_producer.clone();
self.executor self.executor
...@@ -254,6 +254,14 @@ impl Inner { ...@@ -254,6 +254,14 @@ impl Inner {
drop(subscription_handlers); drop(subscription_handlers);
}) })
.detach(); .detach();
} else {
self.executor
.spawn(async move {
// Drop from a different thread to avoid deadlock with recursive dropping
// from within another subscription drop.
drop(subscription_handlers);
})
.detach();
} }
} }
} }
......
...@@ -166,6 +166,8 @@ impl Inner { ...@@ -166,6 +166,8 @@ impl Inner {
self.handlers.close.call_simple(); self.handlers.close.call_simple();
let subscription_handlers: Vec<_> = mem::take(&mut self.subscription_handlers.lock());
if close_request { if close_request {
let channel = self.channel.clone(); let channel = self.channel.clone();
let request = TransportCloseRequest { let request = TransportCloseRequest {
...@@ -174,8 +176,6 @@ impl Inner { ...@@ -174,8 +176,6 @@ impl Inner {
transport_id: self.id, transport_id: self.id,
}, },
}; };
let subscription_handlers: Vec<_> =
mem::take(&mut self.subscription_handlers.lock());
self.executor self.executor
.spawn(async move { .spawn(async move {
...@@ -188,6 +188,14 @@ impl Inner { ...@@ -188,6 +188,14 @@ impl Inner {
drop(subscription_handlers); drop(subscription_handlers);
}) })
.detach(); .detach();
} else {
self.executor
.spawn(async move {
// Drop from a different thread to avoid deadlock with recursive dropping
// from within another subscription drop.
drop(subscription_handlers);
})
.detach()
} }
} }
} }
......
...@@ -217,6 +217,8 @@ impl Inner { ...@@ -217,6 +217,8 @@ impl Inner {
self.handlers.close.call_simple(); self.handlers.close.call_simple();
let subscription_handler = self.subscription_handler.lock().take();
if close_request { if close_request {
let channel = self.channel.clone(); let channel = self.channel.clone();
let request = TransportCloseRequest { let request = TransportCloseRequest {
...@@ -225,7 +227,6 @@ impl Inner { ...@@ -225,7 +227,6 @@ impl Inner {
transport_id: self.id, transport_id: self.id,
}, },
}; };
let subscription_handler = self.subscription_handler.lock().take();
self.executor self.executor
.spawn(async move { .spawn(async move {
...@@ -238,6 +239,14 @@ impl Inner { ...@@ -238,6 +239,14 @@ impl Inner {
drop(subscription_handler); drop(subscription_handler);
}) })
.detach(); .detach();
} else {
self.executor
.spawn(async move {
// Drop from a different thread to avoid deadlock with recursive dropping
// from within another subscription drop.
drop(subscription_handler);
})
.detach();
} }
} }
} }
......
...@@ -254,6 +254,8 @@ impl Inner { ...@@ -254,6 +254,8 @@ impl Inner {
self.handlers.close.call_simple(); self.handlers.close.call_simple();
let subscription_handler = self.subscription_handler.lock().take();
if close_request { if close_request {
let channel = self.channel.clone(); let channel = self.channel.clone();
let request = TransportCloseRequest { let request = TransportCloseRequest {
...@@ -262,7 +264,6 @@ impl Inner { ...@@ -262,7 +264,6 @@ impl Inner {
transport_id: self.id, transport_id: self.id,
}, },
}; };
let subscription_handler = self.subscription_handler.lock().take();
self.executor self.executor
.spawn(async move { .spawn(async move {
...@@ -275,6 +276,14 @@ impl Inner { ...@@ -275,6 +276,14 @@ impl Inner {
drop(subscription_handler); drop(subscription_handler);
}) })
.detach(); .detach();
} else {
self.executor
.spawn(async move {
// Drop from a different thread to avoid deadlock with recursive dropping
// from within another subscription drop.
drop(subscription_handler);
})
.detach();
} }
} }
} }
......
...@@ -324,6 +324,8 @@ impl Inner { ...@@ -324,6 +324,8 @@ impl Inner {
self.handlers.close.call_simple(); self.handlers.close.call_simple();
let subscription_handler = self.subscription_handler.lock().take();
if close_request { if close_request {
let channel = self.channel.clone(); let channel = self.channel.clone();
let request = ProducerCloseRequest { let request = ProducerCloseRequest {
...@@ -333,17 +335,24 @@ impl Inner { ...@@ -333,17 +335,24 @@ impl Inner {
producer_id: self.id, producer_id: self.id,
}, },
}; };
let subscription_handler = self.subscription_handler.lock().take();
self.executor self.executor
.spawn(async move { .spawn(async move {
if let Err(error) = channel.request(request).await { if let Err(error) = channel.request(request).await {
error!("producer closing failed on drop: {}", error); error!("producer closing failed on drop: {}", error);
// Drop from a different thread to avoid deadlock with recursive dropping
// from within another subscription drop.
drop(subscription_handler);
} }
// Drop from a different thread to avoid deadlock with recursive dropping
// from within another subscription drop.
drop(subscription_handler);
})
.detach();
} else {
self.executor
.spawn(async move {
// Drop from a different thread to avoid deadlock with recursive dropping
// from within another subscription drop.
drop(subscription_handler);
}) })
.detach(); .detach();
} }
......
...@@ -301,6 +301,8 @@ impl Inner { ...@@ -301,6 +301,8 @@ impl Inner {
self.handlers.close.call_simple(); self.handlers.close.call_simple();
let subscription_handler = self.subscription_handler.lock().take();
if close_request { if close_request {
let channel = self.channel.clone(); let channel = self.channel.clone();
let request = TransportCloseRequest { let request = TransportCloseRequest {
...@@ -309,7 +311,6 @@ impl Inner { ...@@ -309,7 +311,6 @@ impl Inner {
transport_id: self.id, transport_id: self.id,
}, },
}; };
let subscription_handler = self.subscription_handler.lock().take();
self.executor self.executor
.spawn(async move { .spawn(async move {
...@@ -322,6 +323,14 @@ impl Inner { ...@@ -322,6 +323,14 @@ impl Inner {
drop(subscription_handler); drop(subscription_handler);
}) })
.detach(); .detach();
} else {
self.executor
.spawn(async move {
// Drop from a different thread to avoid deadlock with recursive dropping
// from within another subscription drop.
drop(subscription_handler);
})
.detach();
} }
} }
} }
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论