mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
fix(net): handle panic on Windows for Unix socket usage in Deno.serve() (#24423)
This PR addresses the issue where Deno.serve() panics on Windows when trying to use a Unix socket. Fixes #21967
This commit is contained in:
parent
77c5a336ad
commit
c11e2c74e8
2 changed files with 43 additions and 4 deletions
|
@ -158,14 +158,28 @@ mod ops_unix {
|
||||||
macro_rules! stub_op {
|
macro_rules! stub_op {
|
||||||
($name:ident) => {
|
($name:ident) => {
|
||||||
#[op2(fast)]
|
#[op2(fast)]
|
||||||
pub fn $name() {
|
pub fn $name() -> Result<(), std::io::Error> {
|
||||||
panic!("Unsupported on non-unix platforms")
|
let error_msg = format!(
|
||||||
|
"Operation `{:?}` not supported on non-unix platforms.",
|
||||||
|
stringify!($name)
|
||||||
|
);
|
||||||
|
Err(std::io::Error::new(
|
||||||
|
std::io::ErrorKind::Unsupported,
|
||||||
|
error_msg,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
($name:ident<P>) => {
|
($name:ident<P>) => {
|
||||||
#[op2(fast)]
|
#[op2(fast)]
|
||||||
pub fn $name<P: NetPermissions>() {
|
pub fn $name<P: NetPermissions>() -> Result<(), std::io::Error> {
|
||||||
panic!("Unsupported on non-unix platforms")
|
let error_msg = format!(
|
||||||
|
"Operation `{:?}` not supported on non-unix platforms.",
|
||||||
|
stringify!($name)
|
||||||
|
);
|
||||||
|
Err(std::io::Error::new(
|
||||||
|
std::io::ErrorKind::Unsupported,
|
||||||
|
error_msg,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -4034,3 +4034,28 @@ Deno.test(
|
||||||
await server.finished;
|
await server.finished;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Deno.test({
|
||||||
|
name: "HTTP Server test (error on non-unix platform)",
|
||||||
|
ignore: Deno.build.os !== "windows",
|
||||||
|
}, async () => {
|
||||||
|
await assertRejects(
|
||||||
|
async () => {
|
||||||
|
const ac = new AbortController();
|
||||||
|
const server = Deno.serve({
|
||||||
|
path: "path/to/socket",
|
||||||
|
handler: (_req) => new Response("Hello, world"),
|
||||||
|
signal: ac.signal,
|
||||||
|
onListen({ path: _path }) {
|
||||||
|
console.log(`Server started at ${_path}`);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
server.finished.then(() => console.log("Server closed"));
|
||||||
|
console.log("Closing server...");
|
||||||
|
ac.abort();
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 100)); // Example of awaiting something
|
||||||
|
},
|
||||||
|
Error,
|
||||||
|
'Operation `"op_net_listen_unix"` not supported on non-unix platforms.',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue