facebook/flow · error

Daemon::set_context: bincode serialize context

Error message

Daemon::set_context: bincode serialize context

What it means

Panics when bincode cannot serialize the daemon startup context into the NamedTempFile created for it (daemon_param_<pid>_ in the temp dir). Context is statically Serialize, so the realistic failure is the I/O half of encode_into_std_write: the temp file is unwritable, deleted underneath the process, or the volume is full. The file is later read by the forked+exec'd child to reconstruct context.

Source

Thrown at rust_port/crates/flow_daemon/src/daemon.rs:262

            .expect("Daemon::set_context: bincode serialize param");
        let context = Context {
            parent_in_addr,
            parent_out_addr,
            token,
            param_bytes,
        };
        // Include the PID in the prefix so that forked processes (which share
        // OCaml's internal Filename PRNG state) generate distinct temp names.
        let prefix = format!("daemon_param_{}_", std::process::id());
        let temp_dir = sys_utils::temp_dir_name();
        let temp_file = NamedTempFile::with_prefix_in(&prefix, &temp_dir)?;
        let path = temp_file.path().to_owned();
        // Use `persist` to keep the file after `temp_file` drops; the child
        // is responsible for deleting it (mirrors `daemon.ml:122
        // `Sys.remove file` in `get_context`).
        let (mut file, _path) = temp_file.keep().map_err(|e| e.error)?;
        bincode::serde::encode_into_std_write(&context, &mut file, bincode::config::legacy())
            .expect("Daemon::set_context: bincode serialize context");
        file.flush()?;
        Ok(path)
    }

    // How this works on Unix: It may appear like we are passing file descriptors
    // from one process to another here, but in_handle / out_handle are actually
    // file descriptors that are already open in the current process -- they were
    // created by the parent process before it did fork + exec. However, since
    // exec causes the child to "forget" everything, we have to pass the numbers
    // of these file descriptors as arguments.
    //
    // I'm not entirely sure what this does on Windows.
    pub(crate) fn get_context() -> Option<(String, Context)> {
        let entry = std::env::var(ENV_DAEMON).ok().filter(|s| !s.is_empty())?;
        let file = std::env::var(ENV_DAEMON_PARAM)
            .ok()
            .filter(|s| !s.is_empty())?;
        let bytes =

View on GitHub (pinned to f88ac94bcf)

Solutions

  1. Free space in or enlarge the temp volume (/tmp tmpfs size, disk quota), or set TMPDIR to a writable location with headroom
  2. Retry the spawn: the temp file is per-PID prefixed, so a fresh attempt creates a new file
  3. Check ulimit -f (file size limit) and permissions on the temp dir if it persists

Example fix

// before — panics inside set_context on a full temp dir
let ctx_path = daemon::set_context(&context, &handles)?;

// after — probe the temp dir first, give an actionable error
let tmp = sys_utils::temp_dir_name();
if tempfile::NamedTempFile::new_in(&tmp).is_err() {
    return Err(anyhow::anyhow!("temp dir {tmp:?} not writable; set TMPDIR"));
}
let ctx_path = daemon::set_context(&context, &handles)?;
Defensive patterns

Strategy: validation

Validate before calling

// Probe the temp dir before spawning the daemon
let tmp = sys_utils::temp_dir_name();
if tempfile::NamedTempFile::new_in(&tmp).is_err() {
    return Err(anyhow::anyhow!("temp dir {tmp:?} not writable/full; set TMPDIR"));
}

Prevention

When it happens

Trigger: Calling Daemon::set_context (daemon spawn) when the temp dir reported by sys_utils::temp_dir_name is full (small tmpfs in a container); TMPDIR/TEMP points to a read-only or quota-limited location; a concurrent tmpwatcher/systemd-tmpfiles removes the daemon_param_* file between creation and write.

Common situations: Docker images with a tiny /tmp tmpfs; CI runners with exhausted disk quota; macOS automated tmp cleanup racing a slow spawn; TMPDIR inherited from a hardened service unit pointing somewhere non-writable.

Related errors


AI-assisted analysis of facebook/flow@f88ac94bcf (2026-08-20). Data as JSON: /api/errors/26fe796cd7bd4fe7. Report an issue: GitHub.