diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2021-08-16 13:43:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-16 13:43:43 +0200 |
commit | d1d2388d7f1a09fd2469b356f00b6b361269a0b7 (patch) | |
tree | 31c9939eb8376e1c881d7a3d303cdd80284773e5 /ext/http/lib.rs | |
parent | 163f2ef57117afd410f03be7e7519fc89bd18173 (diff) |
test(ext/http): add test for incomplete HTTP message and fix resource leak (#11717)
This commit adds a test case for "Http: connection closed before
message completed" error as well as fixing an edge with resource
leak when the error is raised.
Diffstat (limited to 'ext/http/lib.rs')
-rw-r--r-- | ext/http/lib.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/ext/http/lib.rs b/ext/http/lib.rs index 8e9142345..8221a6b0d 100644 --- a/ext/http/lib.rs +++ b/ext/http/lib.rs @@ -436,17 +436,33 @@ async fn op_http_response( // The only failure mode is the receiver already having dropped its end // of the channel. if response_sender.sender.send(res).is_err() { + if let Some(rid) = maybe_response_body_rid { + let _ = state + .borrow_mut() + .resource_table + .take::<ResponseBodyResource>(rid); + } return Err(type_error("internal communication error")); } - poll_fn(|cx| match conn_resource.poll(cx) { + let result = poll_fn(|cx| match conn_resource.poll(cx) { Poll::Ready(x) => { state.borrow_mut().resource_table.close(conn_rid).ok(); Poll::Ready(x) } Poll::Pending => Poll::Ready(Ok(())), }) - .await?; + .await; + + if let Err(e) = result { + if let Some(rid) = maybe_response_body_rid { + let _ = state + .borrow_mut() + .resource_table + .take::<ResponseBodyResource>(rid); + } + return Err(e); + } if maybe_response_body_rid.is_none() { conn_resource.deno_service.waker.wake(); |