You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider the following example, adapted from k-websocket. The main change is using a loop in the websocket handler to continuously receive messages:
let home =<html><body><script>
var socket =newWebSocket("ws://"+ window.location.host +"/websocket");
socket.onopen = function () {
socket.send("Hello?");
};
socket.onmessage = function (e) {
console.log(e.data)
};
</script></body></html>let()=Dream.run ~port:8081@@Dream.logger
@@Dream.router [
Dream.get "/"
(fun_ ->
Dream.html home);
Dream.get "/websocket"
(fun_ ->
Dream.websocket (funwebsocket ->
letrec loop=fun() ->
match%lwt Dream.receive websocket with|Somex ->
let%lwt ()=Dream.send websocket x in
loop ()|None ->
Lwt.return ()in
loop ()
));
]
Opening up localhost:8081 on chromium (see logs below), and refreshing the page multiple times makes the dream server eventually hang; everytime. It seems that it detects that the connection was closed when the page was refreshed, but never got to receiving the new request to /websocket.
This is what the logs contain eventually. Here, it hangs after one refresh, but it can take up to 20 refreshes to hang:
19.01.25 01:01:43.731 Running at http://localhost:8081
19.01.25 01:01:43.731 Type Ctrl+C to stop
19.01.25 01:01:48.511 dream.logger INFO REQ 1 GET / ::1:53282 fd 7 Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
19.01.25 01:01:48.512 dream.logger INFO REQ 1 200 in 708 μs
19.01.25 01:01:48.567 dream.logger INFO REQ 2 GET /websocket ::1:53298 fd 8 Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
19.01.25 01:01:48.567 dream.logger INFO REQ 2 101 in 185 μs
19.01.25 01:01:48.571 REQ 2 incoming message
19.01.25 01:01:48.571 REQ 2 looping
19.01.25 01:01:49.715 dream.logger INFO REQ 3 GET / ::1:53282 fd 7 Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
19.01.25 01:01:49.716 dream.logger INFO REQ 3 200 in 161 μs
19.01.25 01:01:49.726 REQ 2 closed
^C
Looking at the process manager, we see that the dream server uses 100% CPU. Some investigation with perf shows that Lwt.catch is the function where most of the time is spent
I haven't been able to reproduce it with Firefox, with 50+ refreshes.
Trying with requests from chrome and firefox at the same time makes it hang less on chrome it seems, but I don't have anything conclusive there.
Extra info if it can be helful:
$ ocaml --version
The OCaml toplevel, version 4.14.2
$ opam list | grep dream
dream 1.0.0~alpha7 Tidy, feature-complete Web framework
dream-httpaf 1.0.0~alpha3 Internal: shared http/af stack for Dream (server) and Hyper (client)
dream-pure 1.0.0~alpha2 Internal: shared HTTP types for Dream (server) and Hyper (client)
$ uname -a
Linux localhost 6.11.10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.11.10-1 (2024-11-23) x86_64 GNU/Linux
The text was updated successfully, but these errors were encountered:
Hi!
Consider the following example, adapted from
k-websocket
. The main change is using a loop in the websocket handler to continuously receive messages:Opening up localhost:8081 on chromium (see logs below), and refreshing the page multiple times makes the dream server eventually hang; everytime. It seems that it detects that the connection was closed when the page was refreshed, but never got to receiving the new request to /websocket.
This is what the logs contain eventually. Here, it hangs after one refresh, but it can take up to 20 refreshes to hang:
Looking at the process manager, we see that the dream server uses 100% CPU. Some investigation with
perf
shows that Lwt.catch is the function where most of the time is spentI haven't been able to reproduce it with Firefox, with 50+ refreshes.
Trying with requests from chrome and firefox at the same time makes it hang less on chrome it seems, but I don't have anything conclusive there.
Extra info if it can be helful:
The text was updated successfully, but these errors were encountered: