mirror of
https://mirror.suhoan.cn/https://github.com/EasyTier/EasyTier.git
synced 2025-12-12 20:57:26 +08:00
fix dead lock in tokio smoltcp (#1270)
This commit is contained in:
@@ -118,10 +118,19 @@ impl TcpStream {
|
|||||||
) -> io::Result<TcpStream> {
|
) -> io::Result<TcpStream> {
|
||||||
let handle = reactor.socket_allocator().new_tcp_socket();
|
let handle = reactor.socket_allocator().new_tcp_socket();
|
||||||
|
|
||||||
reactor
|
// see https://github.com/spacemeowx2/tokio-smoltcp/pull/12
|
||||||
.get_socket::<tcp::Socket>(*handle)
|
let connect_result = {
|
||||||
.connect(&mut reactor.context(), remote_endpoint, local_endpoint)
|
// Issue #11. We must lock the context before we call connect to
|
||||||
.map_err(map_err)?;
|
// avoid lock inversion deadlocks, but drop it before constructing
|
||||||
|
// the TcpStream to avoid a second mutable borror of the reactor.
|
||||||
|
let mut context = reactor.context();
|
||||||
|
reactor.get_socket::<tcp::Socket>(*handle).connect(
|
||||||
|
&mut context,
|
||||||
|
remote_endpoint,
|
||||||
|
local_endpoint,
|
||||||
|
)
|
||||||
|
};
|
||||||
|
connect_result.map_err(map_err)?;
|
||||||
|
|
||||||
let local_addr = ep2sa(&local_endpoint);
|
let local_addr = ep2sa(&local_endpoint);
|
||||||
let peer_addr = ep2sa(&remote_endpoint);
|
let peer_addr = ep2sa(&remote_endpoint);
|
||||||
|
|||||||
Reference in New Issue
Block a user