summaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
Diffstat (limited to 'std')
-rw-r--r--std/http/server.ts4
-rw-r--r--std/http/server_test.ts14
2 files changed, 17 insertions, 1 deletions
diff --git a/std/http/server.ts b/std/http/server.ts
index deedb0f12..ce32511b1 100644
--- a/std/http/server.ts
+++ b/std/http/server.ts
@@ -371,7 +371,9 @@ export class Server implements AsyncIterable<ServerRequest> {
): AsyncIterableIterator<ServerRequest> {
if (this.closing) return;
// Wait for a new connection.
- const conn = await this.listener.accept();
+ const { value, done } = await this.listener.next();
+ if (done) return;
+ const conn = value as Conn;
// Try to accept another connection and add it to the multiplexer.
mux.add(this.acceptConnAndIterateHttpRequests(mux));
// Yield the requests that arrive on the just-accepted connection.
diff --git a/std/http/server_test.ts b/std/http/server_test.ts
index 5baeaa144..c8d4080ca 100644
--- a/std/http/server_test.ts
+++ b/std/http/server_test.ts
@@ -14,6 +14,7 @@ import {
ServerRequest,
writeResponse,
readRequest,
+ serve,
parseHTTPVersion
} from "./server.ts";
import { delay } from "../util/async.ts";
@@ -580,4 +581,17 @@ test({
}
});
+test({
+ name: "[http] close server while iterating",
+ async fn(): Promise<void> {
+ const server = serve(":8123");
+ const nextWhileClosing = server[Symbol.asyncIterator]().next();
+ server.close();
+ assertEquals(await nextWhileClosing, { value: undefined, done: true });
+
+ const nextAfterClosing = server[Symbol.asyncIterator]().next();
+ assertEquals(await nextAfterClosing, { value: undefined, done: true });
+ }
+});
+
runIfMain(import.meta);