Skip to content

Prevent parallel functions from forking Ark#1308

Merged
lionel- merged 2 commits into
mainfrom
ark/fork-guards
Jul 3, 2026
Merged

Prevent parallel functions from forking Ark#1308
lionel- merged 2 commits into
mainfrom
ark/fork-guards

Conversation

@lionel-

@lionel- lionel- commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Addresses posit-dev/positron#3817

This shims mcfork(), the forking primitive used by all entry points in the parallel package. The shim fails with an informative R error.

In addition, makeForkCluster() is also shimmed because it swallows mcfork() errors with an uninformative message.

If mc.cores is set to 1, mcfork() is not called as the {parallel} function falls back to serial computation, which is the same behaviour as on Windows where forking is not possible.

Positron Release Notes

New Features

  • N/A

Bug Fixes

@lionel- lionel- requested a review from thomasp85 July 1, 2026 15:55

@thomasp85 thomasp85 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - I assume the suggestion from Kevin was not possible and we must error here?

@DavisVaughan DavisVaughan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems nice to me too! Was just curious about how it worked so did a drive by review

@lionel-

lionel- commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

@thomasp85 @kevinushey Kevin's suggestion could work in principle but to get it 100% reliable would be a lot of work.

We could start by swapping all R frontend methods like read-console or write-console to no-ops. This would handle code that does print(). Then we could swap .ps.Call() by an erroring version to prevent R callbacks into Ark from reaching code that could hang or be unstable in the forked process.

But what about all the background threads, various R hooks that we might forgot, etc? This would require a large audit and comprehensive testing to get right. And this is just the beginning, because we've then introduced a permanent invariant that the process might be forked that we need to keep in mind as we keep developing Ark.

The parallel computing landscape is now in a different place than 10 years ago, so it seems reasonable to fail with an error and recommend other solutions such as mirai/purrr.

@lionel- lionel- merged commit 3fc2f0c into main Jul 3, 2026
17 checks passed
@lionel- lionel- deleted the ark/fork-guards branch July 3, 2026 08:44
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants