mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 23:34:47 -05:00
fix(cli): suppress 'WSANOTINITIALIZED' error on Deno exit (#7408)
Unblocks: #6901
This commit is contained in:
parent
a3bcdb2b69
commit
839c59b14f
2 changed files with 22 additions and 5 deletions
|
@ -79,8 +79,7 @@ semver-parser = "0.9.0"
|
||||||
uuid = { version = "0.8.1", features = ["v4"] }
|
uuid = { version = "0.8.1", features = ["v4"] }
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
winapi = { version = "0.3.9", features = ["knownfolders", "objbase", "shlobj",
|
winapi = { version = "0.3.9", features = ["knownfolders", "mswsock", "objbase", "shlobj", "tlhelp32", "winbase", "winerror", "winsock2"] }
|
||||||
"winbase", "winerror", "tlhelp32"] }
|
|
||||||
fwdansi = "1.1.0"
|
fwdansi = "1.1.0"
|
||||||
|
|
||||||
[target.'cfg(unix)'.dependencies]
|
[target.'cfg(unix)'.dependencies]
|
||||||
|
|
|
@ -137,9 +137,27 @@ async fn server(
|
||||||
host: SocketAddr,
|
host: SocketAddr,
|
||||||
register_inspector_rx: UnboundedReceiver<InspectorInfo>,
|
register_inspector_rx: UnboundedReceiver<InspectorInfo>,
|
||||||
) {
|
) {
|
||||||
// TODO: `inspector_map` in an Rc<RefCell<T>> instead. This is currently not
|
// When the main thread shuts down, The Rust stdlib will call `WSACleanup()`,
|
||||||
// possible because warp requires all filters to implement Send, which should
|
// which shuts down the network stack. This thread will still be
|
||||||
// not be necessary because we are using a single-threaded runtime.
|
// running at that time (because it never exits), but all attempts at network
|
||||||
|
// I/O will fail with a `WSANOTINITIALIZED` error, which causes a panic.
|
||||||
|
// To prevent this from happening, Winsock is initialized another time here;
|
||||||
|
// this increases Winsock's internal reference count, so it won't shut
|
||||||
|
// itself down when the main thread calls `WSACleanup()` upon exit.
|
||||||
|
// TODO: When the last `Inspector` instance is dropped, make it signal the
|
||||||
|
// server thread so it exits cleanly, then join it with the main thread.
|
||||||
|
#[cfg(windows)]
|
||||||
|
unsafe {
|
||||||
|
use winapi::um::winsock2::{WSAStartup, WSADATA};
|
||||||
|
let mut wsa_data = MaybeUninit::<WSADATA>::zeroed();
|
||||||
|
let r = WSAStartup(0x202 /* Winsock 2.2 */, wsa_data.as_mut_ptr());
|
||||||
|
assert_eq!(r, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: put the `inspector_map` in an `Rc<RefCell<_>>` instead. This is
|
||||||
|
// currently not possible because warp requires all filters to implement
|
||||||
|
// `Send`, which should not be necessary because we are using the
|
||||||
|
// single-threaded Tokio runtime.
|
||||||
let inspector_map = HashMap::<Uuid, InspectorInfo>::new();
|
let inspector_map = HashMap::<Uuid, InspectorInfo>::new();
|
||||||
let inspector_map = Arc::new(Mutex::new(inspector_map));
|
let inspector_map = Arc::new(Mutex::new(inspector_map));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue