-
Notifications
You must be signed in to change notification settings - Fork 176
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_unix.fork not canceling pending promises #789
Comments
The "jobs" that are canceled are the Unix system call jobs being run by Iterations over lists, and any other operations on promises, lists, or other pure-OCaml data structures aren't individual system calls and aren't considered "jobs" in the sense meant here by the docs, and they are not canceled or in any way affected by In the program in the comment, the child inherits the list iteration in both the Does this help to explain the behavior? The documentation of |
Thank you for your clear answer. In the legacy code I'm working on, we were using nested |
There is no way to unschedule pending promises (in fact, Lwt is not aware of all such promises in general, as it has no central list of pending promises. They are just retained in memory by the various pointers between objects in the heap, and are found in the user's stack and data structures. We could add an API to "cancel" (or just abandon) all pending promises that the results of Line 19 in 0f9b94e
and we would just need to expose a function to clear that list when the user wants. That should achieve the same effect as a nested Lines 37 to 41 in 4340664
So if the same callback had been triggered from a different place (such as an ordinary callback triggered by I/O resolution), without this in the recent history of the stack, or if earlier processing inside this iteration over yielded promises had added new yielded promises, the nested Personally, when an Lwt user, I tend to avoid using Lwt after |
Indeed I was thinking about abandoning yielded promises. |
The documentation
Lwt_unix.fork
claims thatHowever it seems it is not entirely the case, as demonstrated by the example bellow.
In this example I fork processes in a parallel iteration over a list. I expect that only the main process forks new jobs, however some forked processes do fork again while they obviously shouldn't.
With sequential iteration on the list, the problematic behavior does not happen.
Warning: Don't increase the size of the list, it rapidly leads to a fork bomb that exhausts available pids which crashes the system.
Tested with Lwt 4.2.1(ocaml 4.07.1) and 5.3.0 (ocaml 4.10.0).
The text was updated successfully, but these errors were encountered: