denoland/deno · error

invalid vsock cid

Error message

invalid vsock cid

What it means

Deno's cron subsystem can delegate cron scheduling to an external scheduler over a socket, configured via the DENO_UNSTABLE_CRON_SOCK environment variable (ext/cron/handler_impl.rs:19). Addresses take the form scheme:detail; for the 'vsock' scheme the detail must be 'cid:port', where cid is a decimal u32, and the literal '-1' is accepted and mapped to u32::MAX (VMADDR_CID_ANY). This io::ErrorKind::InvalidInput error is returned when the cid segment fails to parse as u32.

Source

Thrown at ext/cron/socket.rs:388

    #[cfg(any(
      target_os = "android",
      target_os = "linux",
      target_os = "macos"
    ))]
    Some(("vsock", addr)) => {
      use tokio_vsock::VsockAddr;
      use tokio_vsock::VsockStream;
      let (cid, port) = addr.split_once(':').ok_or_else(|| {
        std::io::Error::new(
          std::io::ErrorKind::InvalidInput,
          "invalid vsock addr",
        )
      })?;
      let cid = if cid == "-1" {
        u32::MAX
      } else {
        cid.parse().map_err(|_| {
          std::io::Error::new(
            std::io::ErrorKind::InvalidInput,
            "invalid vsock cid",
          )
        })?
      };
      let port = port.parse().map_err(|_| {
        std::io::Error::new(
          std::io::ErrorKind::InvalidInput,
          "invalid vsock port",
        )
      })?;
      let stream = tokio::time::timeout(
        std::time::Duration::from_secs(5),
        VsockStream::connect(VsockAddr::new(cid, port)),
      )
      .await??;
      Ok(SocketStream::Vsock(stream))
    }

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Write the address as vsock:CID:PORT with a decimal CID, e.g. DENO_UNSTABLE_CRON_SOCK='vsock:3:5000'
  2. Use the special CID -1 for VMADDR_CID_ANY: 'vsock:-1:5000'
  3. For non-vsock schedulers use 'tcp:host:port' or 'unix:/path/to/sock'
  4. Unset DENO_UNSTABLE_CRON_SOCK to fall back to the local in-process cron handler

Example fix

# before
DENO_UNSTABLE_CRON_SOCK='vsock:0x0003:5000' deno run app.ts
# Error: invalid vsock cid

# after
DENO_UNSTABLE_CRON_SOCK='vsock:3:5000' deno run app.ts
Defensive patterns

Strategy: validation

Validate before calling

const addr = Deno.env.get('DENO_UNSTABLE_CRON_SOCK');
if (addr?.startsWith('vsock:')) {
  const m = addr.match(/^vsock:(-1|\d{1,10}):(\d{1,10})$/);
  if (!m || Number(m[1]) > 0xFFFFFFFF || Number(m[2]) > 0xFFFFFFFF) {
    throw new Error(
      `Invalid vsock cron socket address '${addr}'; expected vsock:CID:PORT with decimal u32 CID and port`,
    );
  }
}

Prevention

When it happens

Trigger: Setting DENO_UNSTABLE_CRON_SOCK to a vsock address whose CID part is neither a decimal u32 nor '-1': 'vsock:0x3:5000' (hex), 'vsock:-2:5000' (negative other than -1), 'vsock:3.5:5000' (float), 'vsock::5000' (empty), 'vsock:myhost:5000' (hostname), or a CID above 4294967295. The parse runs in connect_to_socket() when Deno first connects the SocketCronHandler to register a Deno.cron() job.

Common situations: Running Deno inside a VM sandbox that syncs cron state over AF_VSOCK (Firecracker/gVisor-style environments); an orchestrator or CI injecting DENO_UNSTABLE_CRON_SOCK with a host:port value that someone merely prefixed with 'vsock:'; trailing whitespace or a newline in the injected variable.

Related errors


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