influxdata/influxdb · error · HeapDumpError::BadTempPath

tempfile path was not valid C string (non-utf8 or interior…

Error message

tempfile path was not valid C string (non-utf8 or interior NUL)

What it means

HeapDumpError::BadTempPath is returned by dump_heap_profile in the jemalloc_stats crate when the temporary file created for the heap profile dump cannot be passed to jemalloc as a C string. jemalloc's prof.dump option requires a NUL-terminated path, so the tempfile path must be valid UTF-8 with no interior NUL bytes. If either condition fails, the path is rejected before any dump is attempted.

Solutions

  1. Ensure TMPDIR (and the OS temp directory) is a plain UTF-8 path without special characters and restart the process
  2. Verify the environment with `echo $TMPDIR` and `printf %q`, correcting any odd bytes
  3. If the path is genuinely valid, report a bug: the tempfile crate's path handling may need inspection

Example fix

// before
TMPDIR=/tmp/naïve$'\x01'dir myapp
// after
TMPDIR=/tmp myapp
Defensive patterns

Strategy: validation

Validate before calling

fn temp_path_is_c_string() -> bool {
    std::env::var("TMPDIR").map(|d| std::path::Path::new(&d).is_dir() && !d.contains('\0') && d.is_ascii()).unwrap_or(true)
}

Type guard

fn valid_c_string(p: &std::path::Path) -> bool {
    p.to_str().map(|s| !s.contains('\0')).unwrap_or(false)
}

Try / catch

match dump_heap_profile().await {
    Err(HeapDumpError::BadTempPath) => eprintln!("fix TMPDIR: must be valid UTF-8 without NUL"),
    other => other?,
}

Prevention

When it happens

Trigger: Calling dump_heap_profile() (or the pprof HTTP endpoint backed by it) on a system where the temp directory resolves to a path containing non-UTF-8 bytes or an embedded NUL character.

Common situations: TMPDIR or the OS temp-dir environment pointing at a directory with non-UTF-8 bytes; unusual locale setups in containers; paths constructed programmatically with embedded NULs.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of influxdata/influxdb@06200ef96b (2026-09-19). Data as JSON: /api/errors/d609fe8c482ee737. Report an issue: GitHub.

Appendix: source

Thrown at core/jemalloc_stats/src/lib.rs:92

/// `tikv-jemalloc-sys` prefixes the `MALLOC_CONF` env name on the platforms
/// in its `NO_UNPREFIXED_MALLOC_TARGETS` list, so the right name to suggest
/// in a user-facing message differs by build target.
pub const MALLOC_CONF_ENV: &str = if cfg!(any(
    target_os = "macos",
    target_os = "ios",
    target_os = "android",
    target_os = "dragonfly",
    target_env = "musl",
)) {
    "_RJEM_MALLOC_CONF"
} else {
    "MALLOC_CONF"
};

/// Errors returned by [`dump_heap_profile`].
#[derive(Debug, thiserror::Error)]
pub enum HeapDumpError {
    #[error("tempfile path was not valid C string (non-utf8 or interior NUL)")]
    BadTempPath,
    #[error("heap profiling is disabled; restart with {MALLOC_CONF_ENV}=prof:true to enable")]
    ProfilingDisabled,
    #[error("jemalloc prof.dump failed: {0}")]
    Jemalloc(#[from] tikv_jemalloc_ctl::Error),
    #[error("tempfile i/o: {0}")]
    Io(#[from] std::io::Error),
    #[error("blocking task join: {0}")]
    Join(#[from] tokio::task::JoinError),
}

/// Trigger a jemalloc heap profile dump and return a streaming reader for
/// the resulting `heap_v2` bytes.
///
/// Requires jemalloc built with `--enable-prof` (i.e. `tikv-jemallocator`
/// `profiling` feature) AND the binary started with `prof:true` in the
/// platform-appropriate `MALLOC_CONF` env var (or via a baked-in
/// `malloc_conf` static — see [`DEFAULT_MALLOC_CONF`]). When profiling is

View on GitHub (pinned to 06200ef96b)