anmonteiro / anmonteiro/httpun-ws

`Eio.Switch.run` hangs cleaning up resources of failed websocket connection

未关闭
#74 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
OCaml
星标
29
派生
16
PR 合并指标
30 天内没有已合并 PR

描述

Using the wscat example modified to resolve the promise on error, and with some extra logging:

```diff
diff --git a/examples/eio/wscat.ml b/examples/eio/wscat.ml
index ad6b645..573872e 100644
--- a/examples/eio/wscat.ml
+++ b/examples/eio/wscat.ml
@@ -30,9 +30,10 @@ let websocket_handler env ~sw u wsd =
; eof
}

-let error_handler = function
+let error_handler u = function
| `Handshake_failure (rsp, _body) ->
- Format.eprintf "Handshake failure: %a\n%!" Httpun.Response.pp_hum rsp
+ Format.eprintf "Handshake failure: %a\n%!" Httpun.Response.pp_hum rsp;
+ Promise.resolve u ();
| _ -> assert false

let () =
@@ -78,7 +79,11 @@ let () =
~host
~port
~resource
- ~error_handler
+ ~error_handler:(error_handler u)
~websocket_handler:(websocket_handler env ~sw u)
in
- Promise.await p))
+ Promise.await p;
+ Format.eprintf "After Promise.await\n%!"
+ );
+ Format.eprintf "After Switch.run\n%!"
+ )
```

With a random server that doesn't accept websocket connections, the promise resolves, but the `Eio.Switch.run` never returns (presumable because there are hanging fibers):

```
% dune exec ./examples/eio/wscat.exe 136.244.81.69
Handshake failure: ((version "HTTP/1.1") (status 404) (reason "Not Found") (headers
(("Date" "Tue, 10 Sep 2024 23:04:03 GMT")
("Content-Type" "text/html; charset=utf-8")("Content-Length" "146")
("Connection" "keep-alive"))))
After Promise.await
```

Note that `websocket_handler` is never called, so I don't think it's the input reading loop.

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。