xai-org/grok-build · error

blocking pre-allocate task panicked: {e}

Error message

blocking pre-allocate task panicked: {e}

What it means

try_parallel_download pre-allocates the output file to its full size using tokio::task::spawn_blocking; if the blocking task itself panics (JoinError), this error wraps the panic message. The `??` after the map_err means an inner io::Error still propagates as-is, so this error specifically indicates a panic in the spawn_blocking closure (or task cancellation).

Source

Thrown at crates/codegen/xai-grok-update/src/auto_update.rs:1142

                .unwrap()
                .progress_chars("━╸─"),
        );
        Some(pb)
    } else {
        None
    };

    let tmp = tmp_download_path(dest);
    // Pre-allocate so each task can seek+write to its own range concurrently.
    // One blocking-pool hop instead of two per tokio::fs call.
    let tmp_for_alloc = tmp.clone();
    tokio::task::spawn_blocking(move || -> std::io::Result<()> {
        let f = std::fs::File::create(&tmp_for_alloc)?;
        f.set_len(size)?;
        Ok(())
    })
    .await
    .map_err(|e| anyhow::anyhow!("blocking pre-allocate task panicked: {e}"))??;

    let tasks = (0..n_chunks).map(|i| {
        let start = i * chunk_size;
        let end = std::cmp::min(start + chunk_size, size) - 1;
        let url = url.to_string();
        let tmp = tmp.clone();
        let client = client.clone();
        let pb = pb.clone();
        async move { download_range(&client, &url, &tmp, start, end, pb.as_ref()).await }
    });
    let result = futures::future::try_join_all(tasks).await;

    if let Some(pb) = &pb {
        pb.finish_and_clear();
    }

    match result {
        Ok(_) => {

View on GitHub (pinned to bc7f02eddd)

Solutions

  1. Check the `{e}` text for the panic message and any downstream cancellation cause
  2. Ensure the tokio runtime is not shutting down while the download runs (await tasks to completion)
  3. Pre-allocate synchronously or add a single-stream fallback path when pre-allocation fails
  4. Validate the temp file path (tmp_for_alloc) creation conditions before spawning

Example fix

// before
.await
.map_err(|e| anyhow::anyhow!("blocking pre-allocate task panicked: {e}"))??;
// after
.await
.map_err(|e| anyhow::anyhow!("blocking pre-allocate task panicked: {e}"))?
.map_err(|e| anyhow::anyhow!("pre-allocation failed: {e}"))
.map_err(|e| { eprintln!("{} ; falling back to single-stream download", e); e });
Defensive patterns

Strategy: retry

Validate before calling

// ensure runtime stays alive and temp path is valid for the duration
let tmp_for_alloc = tmp.clone();
assert!(!runtime_is_shutting_down(), "abort before spawning blocking tasks");

Try / catch

match download_with_progress(url, &dest).await {
    Err(e) if e.to_string().contains("blocking pre-allocate task panicked") => {
        eprintln!("pre-allocation failed: {e}; retrying with single-stream download");
        download_single_stream(url, &dest).await?;
    }
    other => other,
}

Prevention

When it happens

Trigger: Calling download_with_progress / download_silent when the pre-allocation blocking task panics — e.g. the join handle returned an error due to a panic in File::create/set_len handling, or the runtime is shutting down and cancels the task.

Common situations: Runtime shutdown/rate limiter cancelling blocking tasks mid-download; a panic inside the closure due to an unexpected condition (path handling bug); running under a runtime that disallows or aborts blocking tasks.

Related errors


AI-assisted analysis of xai-org/grok-build@bc7f02eddd (2026-08-31). Data as JSON: /api/errors/c490eef8bd92cece. Report an issue: GitHub.