{"record":{"id":"c490eef8bd92cece","repo":"xai-org/grok-build","slug":"blocking-pre-allocate-task-panicked-e","errorCode":null,"errorMessage":"blocking pre-allocate task panicked: {e}","messagePattern":"blocking pre-allocate task panicked: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-update/src/auto_update.rs","lineNumber":1142,"sourceCode":"                .unwrap()\n                .progress_chars(\"━╸─\"),\n        );\n        Some(pb)\n    } else {\n        None\n    };\n\n    let tmp = tmp_download_path(dest);\n    // Pre-allocate so each task can seek+write to its own range concurrently.\n    // One blocking-pool hop instead of two per tokio::fs call.\n    let tmp_for_alloc = tmp.clone();\n    tokio::task::spawn_blocking(move || -> std::io::Result<()> {\n        let f = std::fs::File::create(&tmp_for_alloc)?;\n        f.set_len(size)?;\n        Ok(())\n    })\n    .await\n    .map_err(|e| anyhow::anyhow!(\"blocking pre-allocate task panicked: {e}\"))??;\n\n    let tasks = (0..n_chunks).map(|i| {\n        let start = i * chunk_size;\n        let end = std::cmp::min(start + chunk_size, size) - 1;\n        let url = url.to_string();\n        let tmp = tmp.clone();\n        let client = client.clone();\n        let pb = pb.clone();\n        async move { download_range(&client, &url, &tmp, start, end, pb.as_ref()).await }\n    });\n    let result = futures::future::try_join_all(tasks).await;\n\n    if let Some(pb) = &pb {\n        pb.finish_and_clear();\n    }\n\n    match result {\n        Ok(_) => {","sourceCodeStart":1124,"sourceCodeEnd":1160,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-update/src/auto_update.rs#L1124-L1160","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the `{e}` text for the panic message and any downstream cancellation cause","Ensure the tokio runtime is not shutting down while the download runs (await tasks to completion)","Pre-allocate synchronously or add a single-stream fallback path when pre-allocation fails","Validate the temp file path (tmp_for_alloc) creation conditions before spawning"],"exampleFix":"// before\n.await\n.map_err(|e| anyhow::anyhow!(\"blocking pre-allocate task panicked: {e}\"))??;\n// after\n.await\n.map_err(|e| anyhow::anyhow!(\"blocking pre-allocate task panicked: {e}\"))?\n.map_err(|e| anyhow::anyhow!(\"pre-allocation failed: {e}\"))\n.map_err(|e| { eprintln!(\"{} ; falling back to single-stream download\", e); e });","handlingStrategy":"retry","validationCode":"// ensure runtime stays alive and temp path is valid for the duration\nlet tmp_for_alloc = tmp.clone();\nassert!(!runtime_is_shutting_down(), \"abort before spawning blocking tasks\");","typeGuard":null,"tryCatchPattern":"match download_with_progress(url, &dest).await {\n    Err(e) if e.to_string().contains(\"blocking pre-allocate task panicked\") => {\n        eprintln!(\"pre-allocation failed: {e}; retrying with single-stream download\");\n        download_single_stream(url, &dest).await?;\n    }\n    other => other,\n}","preventionTips":["Keep the tokio runtime alive until all spawned tasks complete","Add a single-stream fallback when parallel pre-allocation fails","Validate temp-file path and permissions before spawning blocking tasks","Log JoinError panic messages for root-cause diagnosis"],"tags":["tokio","panic","filesystem","download"],"backgroundTag":"blocking-task-panicked","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}