Skip to content

IPC lifecycle hooks can run on a thread with no VM #569

Description

@singaraiona

Follow-up to #565, which is the NULL guard that makes the no hook installed case safe. This is the question that guard deliberately left open, raised by @vbmithr in the PR.

The gap

ray_ipc_closeray_poll_deregisteripc_on_closehook_call_lifecycle(IPC_HOOK_CLOSE)hook_lookupray_env_get.

With #565 applied, a VM-less thread walking that path skips the local scopes and falls through to the global env. If no hook is bound, hook_lookup returns NULL, hook_call_lifecycle's if (!fn) return; fires, and teardown is the no-op it was always meant to be. That is the case #565 fixes.

But globals do resolve. So if a .ipc.on.close hook is bound and the close happens on a thread that never called ray_runtime_create, hook_lookup now finds the lambda and call_fn1 runs it with __VM == NULL.

Why this needs a decision rather than another guard

Whatever the evaluator does with a null __VM under a hook body is not something to discover by crashing. The honest options:

  1. Don't dispatch. Lifecycle hooks only run on threads with a VM; a VM-less close silently skips the hook. Cheapest, but a user-visible hook silently not firing is its own trap.
  2. Bind a VM for the duration. Dispatch acquires a VM (or a scratch one) around the hook call. Correct, but raises lifetime and cost questions on a teardown path.
  3. Refuse at the boundary. Document ray_ipc_close as owning-thread-only and fail loudly off it.

runtime.c:50-54 already states the project's stance for the error path — FFI callers do reach these paths on threads that never bound a VM — which argues against (3) as a general answer.

Not urgent

Reaching this needs both a bound .ipc.on.close hook and a close driven from a VM-less thread. #565 covers the common case. Filing so the decision is recorded rather than found later.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions