1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-25 00:29:09 -05:00

fix(ext/flash): panic on AddrInUse (#15607)

This commit is contained in:
Bartek Iwańczuk 2022-08-26 05:12:11 +02:00 committed by GitHub
parent 376665d115
commit da10c9c8d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 6 deletions

View file

@ -57,6 +57,35 @@ Deno.test(async function httpServerCanResolveHostnames() {
await server; await server;
}); });
Deno.test(async function httpServerRejectsOnAddrInUse() {
const ac = new AbortController();
const listeningPromise = deferred();
const server = Deno.serve({
handler: (_req) => new Response("ok"),
hostname: "localhost",
port: 4501,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
});
assertRejects(
() =>
Deno.serve({
handler: (_req) => new Response("ok"),
hostname: "localhost",
port: 4501,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
}),
Deno.errors.AddrInUse,
);
ac.abort();
await server;
});
Deno.test({ permissions: { net: true } }, async function httpServerBasic() { Deno.test({ permissions: { net: true } }, async function httpServerBasic() {
const ac = new AbortController(); const ac = new AbortController();
const promise = deferred(); const promise = deferred();

View file

@ -28,7 +28,7 @@
const { const {
Function, Function,
ObjectPrototypeIsPrototypeOf, ObjectPrototypeIsPrototypeOf,
PromiseResolve, PromiseAll,
TypedArrayPrototypeSubarray, TypedArrayPrototypeSubarray,
TypeError, TypeError,
Uint8Array, Uint8Array,
@ -249,7 +249,8 @@
core.opAsync("op_flash_wait_for_listening", serverId).then((port) => { core.opAsync("op_flash_wait_for_listening", serverId).then((port) => {
onListen({ hostname: listenOpts.hostname, port }); onListen({ hostname: listenOpts.hostname, port });
}); }).catch(() => {});
const finishedPromise = serverPromise.catch(() => {});
const server = { const server = {
id: serverId, id: serverId,
@ -257,7 +258,7 @@
hostname: listenOpts.hostname, hostname: listenOpts.hostname,
port: listenOpts.port, port: listenOpts.port,
closed: false, closed: false,
finished: PromiseResolve(serverPromise), finished: finishedPromise,
async close() { async close() {
if (server.closed) { if (server.closed) {
return; return;
@ -551,7 +552,10 @@
}, 1000); }, 1000);
} }
return await server.serve().catch(console.error); await PromiseAll([
server.serve().catch(console.error),
serverPromise,
]);
} }
function createRequestBodyStream(serverId, token) { function createRequestBodyStream(serverId, token) {

View file

@ -1313,8 +1313,11 @@ fn op_flash_wait_for_listening(
server_ctx.listening_rx.take().unwrap() server_ctx.listening_rx.take().unwrap()
}; };
Ok(async move { Ok(async move {
let port = listening_rx.recv().await.unwrap(); if let Some(port) = listening_rx.recv().await {
Ok(port) Ok(port)
} else {
Err(generic_error("This error will be discarded"))
}
}) })
} }