{"record":{"id":"6e7d4bf78a20cc58","repo":"influxdata/influxdb","slug":"blocking-task-join-0","errorCode":null,"errorMessage":"blocking task join: {0}","messagePattern":"blocking task join: (.+?)","errorType":"exception","errorClass":"HeapDumpError","httpStatus":null,"severity":"error","filePath":"core/jemalloc_stats/src/lib.rs","lineNumber":100,"sourceCode":"    target_env = \"musl\",\n)) {\n    \"_RJEM_MALLOC_CONF\"\n} else {\n    \"MALLOC_CONF\"\n};\n\n/// Errors returned by [`dump_heap_profile`].\n#[derive(Debug, thiserror::Error)]\npub enum HeapDumpError {\n    #[error(\"tempfile path was not valid C string (non-utf8 or interior NUL)\")]\n    BadTempPath,\n    #[error(\"heap profiling is disabled; restart with {MALLOC_CONF_ENV}=prof:true to enable\")]\n    ProfilingDisabled,\n    #[error(\"jemalloc prof.dump failed: {0}\")]\n    Jemalloc(#[from] tikv_jemalloc_ctl::Error),\n    #[error(\"tempfile i/o: {0}\")]\n    Io(#[from] std::io::Error),\n    #[error(\"blocking task join: {0}\")]\n    Join(#[from] tokio::task::JoinError),\n}\n\n/// Trigger a jemalloc heap profile dump and return a streaming reader for\n/// the resulting `heap_v2` bytes.\n///\n/// Requires jemalloc built with `--enable-prof` (i.e. `tikv-jemallocator`\n/// `profiling` feature) AND the binary started with `prof:true` in the\n/// platform-appropriate `MALLOC_CONF` env var (or via a baked-in\n/// `malloc_conf` static — see [`DEFAULT_MALLOC_CONF`]). When profiling is\n/// disabled at startup this returns [`HeapDumpError::ProfilingDisabled`].\n///\n/// The function handles all file machinery internally: it allocates a\n/// tempfile, runs jemalloc's synchronous `prof.dump`, unlinks the path, and\n/// hands back an open fd wrapped in a [`HeapProfileStream`]. The tempfile\n/// is unlinked before this call returns — POSIX semantics keep the inode\n/// alive via the open fd, so no profile bytes remain on disk after the\n/// stream is dropped.","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/influxdata/influxdb/blob/06200ef96ba82c5f6727e5038a83af8e722c6875/core/jemalloc_stats/src/lib.rs#L82-L118","documentation":"HeapDumpError::Join wraps a tokio::task::JoinError produced when the spawn_blocking task that performs the jemalloc dump is joined by dump_heap_profile and the task failed — either it panicked or the runtime is shutting down. The dump itself may never have completed; this variant reports the async task machinery failure, with the original JoinError available via #[from].","triggerScenarios":"Calling dump_heap_profile() during Tokio runtime shutdown (task cancelled), or when the blocking task panics internally (e.g. jemalloc aborting).","commonSituations":"Graceful shutdown racing an in-flight pprof heap dump request; a panic inside the blocking dump path; running dump_heap_profile outside a Tokio runtime context.","solutions":["Avoid issuing heap dumps during shutdown; guard the endpoint so it rejects once shutdown begins","Inspect the wrapped JoinError (is_panic/is_cancelled) to distinguish panic vs cancellation and fix the underlying panic if present","Ensure dump_heap_profile is always called within an active Tokio runtime"],"exampleFix":"// before\nlet stream = dump_heap_profile().await?;\n// after\nmatch dump_heap_profile().await {\n    Err(HeapDumpError::Join(e)) if e.is_cancelled() => return Err(StatusCode::SERVICE_UNAVAILABLE.into()),\n    other => other?,\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match dump_heap_profile().await {\n    Err(HeapDumpError::Join(e)) if e.is_cancelled() => /* runtime shutting down; skip */,\n    Err(HeapDumpError::Join(e)) => tracing::error!(%e, \"dump task panicked\"),\n    other => other?,\n}","preventionTips":["Reject dump requests once shutdown starts","Never call dump_heap_profile without an active Tokio runtime","Fix panics inside the blocking dump path surfaced by JoinError::is_panic"],"tags":["rust","tokio","spawn-blocking","heap-profiling","task-join"],"backgroundTag":"thread-interrupted","analyzedSha":"06200ef96ba82c5f6727e5038a83af8e722c6875","analyzedAt":"2026-09-19T12:55:30.003Z","contentChangedAt":"2026-09-19T12:55:30.003Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}