summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/tests/unit/http_test.ts20
-rw-r--r--ext/http/lib.rs9
2 files changed, 24 insertions, 5 deletions
diff --git a/cli/tests/unit/http_test.ts b/cli/tests/unit/http_test.ts
index d762a6497..5262c5919 100644
--- a/cli/tests/unit/http_test.ts
+++ b/cli/tests/unit/http_test.ts
@@ -731,3 +731,23 @@ unitTest({ perms: { net: true } }, async function httpCookieConcatenation() {
assertEquals(text, "ok");
await promise;
});
+
+// https://github.com/denoland/deno/issues/11651
+unitTest({ perms: { net: true } }, async function httpServerPanic() {
+ const listener = Deno.listen({ port: 4501 });
+ const client = await Deno.connect({ port: 4501 });
+ const conn = await listener.accept();
+ const httpConn = Deno.serveHttp(conn);
+
+ // This message is incomplete on purpose, we'll forcefully close client connection
+ // after it's flushed to cause connection to error out on the server side.
+ const encoder = new TextEncoder();
+ await client.write(encoder.encode("GET / HTTP/1.1"));
+
+ httpConn.nextRequest();
+ await client.write(encoder.encode("\r\n\r\n"));
+ httpConn.close();
+
+ client.close();
+ listener.close();
+});
diff --git a/ext/http/lib.rs b/ext/http/lib.rs
index 2c858143c..db55ca53d 100644
--- a/ext/http/lib.rs
+++ b/ext/http/lib.rs
@@ -196,13 +196,12 @@ async fn op_http_request_next(
Poll::Ready(Err(e)) => {
// TODO(ry) close RequestResource associated with connection
// TODO(ry) close ResponseBodyResource associated with connection
- // close ConnResource
- state
+ // try to close ConnResource, but don't unwrap as it might
+ // already be closed
+ let _ = state
.borrow_mut()
.resource_table
- .take::<ConnResource>(conn_rid)
- .unwrap();
-
+ .take::<ConnResource>(conn_rid);
if should_ignore_error(&e) {
true
} else {