Skip to content

Conversation

@VegetarianOrc
Copy link
Contributor

@VegetarianOrc VegetarianOrc commented Nov 10, 2025

Raise an assertion error when a Runtime is used by client/worker creation/usage.

What was changed

  • Add fork checks to bridge runtime and raise a RuntimeError if the runtime was created by a different process.
  • Add new _RuntimeRef private class to encapsulate behavior around managing calls to Runtime.default
  • Replace global var of _default_runtime with an instance of the new _RuntimeRef and use it in calls to Runtime.default, Runtime.prevent_default and Runtime.set_default.

Why?

Startup time in large codebases can be challenge to manage. One strategy to manage startup time is to load modules once and then fork the process into many instances so the child process don't need to repeat the startup cost. These changes help users employing that strategy to manage Temporal usage across forks in a safe manner.

Checklist

  1. Closes [Feature Request] Better prevention of accidental Runtime use over forks #1201

  2. How was this tested:

  • Unit tests were added that create a fork and expect an assertion error for the following:
    • creating a client with Client.connect after Runtime.default was called pre-fork
    • using a client created pre-fork
    • creating a worker after Runtime.default was called pre-fork
    • using a worker created pre-fork
  • Unit tests were added to validate behavior of new _RuntimeRef class that the lifecycle of default runtime.
  1. Any docs updates needed?

@VegetarianOrc VegetarianOrc marked this pull request as ready for review November 12, 2025 22:47
@VegetarianOrc VegetarianOrc requested a review from a team as a code owner November 12, 2025 22:47
Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

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

LGTM, non-blocking concern about if we need the entire new RuntimeRef class to add a global boolean

@VegetarianOrc VegetarianOrc merged commit ceb7058 into main Nov 17, 2025
33 of 39 checks passed
@VegetarianOrc VegetarianOrc deleted the prevent-fork branch November 17, 2025 20:22
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

Successfully merging this pull request may close these issues.

[Feature Request] Better prevention of accidental Runtime use over forks

4 participants