haskell-distributed / haskell-distributed/distributed-process

link/unlink is exception unsafe

Open
#286 10 comments 0 reactions 1 assignee View on GitHub

@hyperthunk is already working on this.

Since Nov 9, 2018.

task
Dominant language
Haskell
Stars
751
Forks
99
Avg merge
45m
Merged PRs (30d)
2

Description

Suppose I have the following code

f pid = do
  link pid
  blocking_operations_which_depend_on_health_of pid
  unlink pid

If f is interrupted with an exception, unlink might never be called. Thus I rewrite to:

f pid = bracket_ (link pid) (unlink pid) $
          blocking_operations_which_depend_on_health_of pid

But this still doesn't help, because unlink is interruptible, thus if unlink is interrupted with an exception, the process will remain linked to pid after leaving f.

How about

f pid = bracket_ (link pid) (uninterruptibleMask_ $ unlink pid) $
          blocking_operations_which_depend_on_health_of pid

?

This introduces the potential for blocking indefinitely. If pid dies while unlink is executing, the link exception cannot be thrown because uninterruptibleMask_ is in effect. However, when unlink completes, the exception cannot be thrown either, because the very unlink definition does not allow it. The only way to avoid illegal behavior would be to have unlink never return or somehow don't throw the link exception (the latter looks impossible to me).

The second attempt is the one I would expect to work. The problem is determining what tweak of unlink semantics would make it to work.

I would like unlink to be uninterruptible, but I don't see how that could be implemented. An alternative is to guarantee that when unlink runs with exceptions masked, it always unlinks before returning, but it might return with an exception if it is interrupted during its execution.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.