denoland/deno · error

failed to unregister: {}

Error message

failed to unregister: {}

What it means

On Windows, each spawned child registers a wait object; the Waiting struct unregisters it in Drop via UnregisterWaitEx and panics if the call fails. Drop has no error channel, so a failed unregister aborts instead of leaking the registration silently.

Source

Thrown at runtime/subprocess_windows/src/process.rs:251

      GlobalJobHandle(job)
    }
  });
}

#[derive(Debug)]
struct Waiting {
  rx: oneshot::Receiver<()>,
  wait_object: HANDLE,
  tx: *mut Option<oneshot::Sender<()>>,
}

impl Drop for Waiting {
  fn drop(&mut self) {
    unsafe {
      let rc = UnregisterWaitEx(self.wait_object, INVALID_HANDLE_VALUE);
      if rc == 0 {
        panic!("failed to unregister: {}", io::Error::last_os_error());
      }
      drop(Box::from_raw(self.tx));
    }
  }
}

unsafe impl Sync for Waiting {}
unsafe impl Send for Waiting {}

pub struct SpawnOptions<'a> {
  // pub exit_cb: Option<fn(*const uv_process, u64, i32)>,
  pub flags: u32,
  pub file: Cow<'a, OsStr>,
  pub args: Vec<Cow<'a, OsStr>>,
  pub env: &'a CommandEnv,
  pub cwd: Option<Cow<'a, OsStr>>,
  pub stdio: Vec<super::process_stdio::StdioContainer>,
}

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Drop child/process objects in a clean order before tearing down the runtime
  2. Let the API own internal handles; never clone or duplicate them manually
  3. If embedding, shut down subprocess tracking before dropping the isolate
  4. Report upstream if reproducible - Drop-order failures here are treated as bugs
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Dropping the Waiting registration when its wait handle is already invalid: dropping during process or thread teardown after handles were closed, dropping the registration twice, or runtime shutdown racing the wait thread.

Common situations: Embedders tearing down the runtime while subprocess state is alive; abnormal shutdown paths on Windows; code that duplicates internal handles.

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/0b81e4e888f10944. Report an issue: GitHub.