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
It is rather easy to expect Lwt.protected to work like choose or pick (which remove listeners) and keep adding listeners accidentally to an existing thread when wrapping it with Lwt.protected. This could happen if the user does for example something resembling match_lwt Lwt.pick [Lwt.protected t; Lwt_unix.sleep t0 >> raise_lwt Timeout] (where the t thread is not canceled on timeout, but the timeout thread is on completion).
Iow., is there a reason for the following not to run in constant mem?
let () =
Lwt_main.run begin
let t, _ = Lwt.wait () in
Lwt.on_cancel t (fun () -> print_endline "CANCEL 1");
let rec loop () =
let t' = Lwt.bind (Lwt.protected t) @@ fun () ->
Lwt.return @@ print_endline "X"
in
Lwt.cancel t';
loop ()
in
loop ()
end
The text was updated successfully, but these errors were encountered:
I'm adding for the record (to help future readers looking for help on memory
issues with the currently released Lwt versions) that this also solves
memleaks in Lwt_stream (peek, and probably more functions).
It is rather easy to expect
Lwt.protected
to work likechoose
orpick
(which remove listeners) and keep adding listeners accidentally to an existing thread when wrapping it withLwt.protected
. This could happen if the user does for example something resemblingmatch_lwt Lwt.pick [Lwt.protected t; Lwt_unix.sleep t0 >> raise_lwt Timeout]
(where thet
thread is not canceled on timeout, but the timeout thread is on completion).Iow., is there a reason for the following not to run in constant mem?
The text was updated successfully, but these errors were encountered: