anmonteiro / anmonteiro/httpun-ws

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

Offen
#74 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
OCaml
Sterne
29
Forks
16
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.