Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lwt.protected listeners are not removed from the protected thread on cancel #181

Closed
mfp opened this issue Aug 27, 2015 · 3 comments
Closed

Comments

@mfp
Copy link
Collaborator

mfp commented Aug 27, 2015

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
@aantron
Copy link
Collaborator

aantron commented Jun 29, 2016

Thanks, this was a bug. If interested, see the message of the attached commit for details.

@mfp
Copy link
Collaborator Author

mfp commented Jul 2, 2016

On Tue, Jun 28, 2016 at 06:26:48PM -0700, Anton wrote:

Closed #181 via 616168f.

Thank you.

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).

Mauricio Fernández

@aantron
Copy link
Collaborator

aantron commented Jul 2, 2016

Thanks. Indeed. See, for instance, #56 (also fixed by the commit).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants