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

signal handling calls Lwt_main.run #36

Open
edwintorok opened this issue Oct 5, 2018 · 1 comment
Open

signal handling calls Lwt_main.run #36

edwintorok opened this issue Oct 5, 2018 · 1 comment

Comments

@edwintorok
Copy link
Contributor

See cleanup.ml, it calls Lwt_main.run when handling a signal.
I think this is very fragile and could lock up under some situations, reading the Lwt_main.run documentation it says:

Note that you should avoid using run inside threads

    The calling threads will not resume before run returns.
    Successive invocations of run are serialized: an invocation of run will not terminate before all subsequent invocations are terminated. 

So if we get a signal while the main Lwt_main.run is running the one inside the signal handler wouldn't run at all.

Unfortunately the Lwt documentation is not very clear on how to resolve Lwt promises when triggered from a signal handler, but perhaps the right thing to do would be to use Lwt.async (...) (provided we have an exception handler set up for asynchronous exceptions).

@gaborigloi
Copy link
Contributor

I'm not quite sure about the order in which things happen when we catch the signal
If the Lwt main loop is still running, then we do not need Lwt_main.run
Otherwise, if it is not running at that point, it's safe to run it.

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