{"record":{"id":"597ac11a1cb31a1b","repo":"neondatabase/neon","slug":"heap-profiling-not-enabled","errorCode":null,"errorMessage":"heap profiling not enabled","messagePattern":"heap profiling not enabled","errorType":"http","errorClass":"ApiError","httpStatus":500,"severity":"error","filePath":"libs/http-utils/src/endpoint.rs","lineNumber":483,"sourceCode":"    enum Format {\n        Jemalloc,\n        Pprof,\n        Svg,\n    }\n\n    // Parameters.\n    let format = match get_query_param(&req, \"format\")?.as_deref() {\n        None => Format::Pprof,\n        Some(\"jemalloc\") => Format::Jemalloc,\n        Some(\"pprof\") => Format::Pprof,\n        Some(\"svg\") => Format::Svg,\n        Some(format) => return Err(ApiError::BadRequest(anyhow!(\"invalid format {format}\"))),\n    };\n\n    // Obtain profiler handle.\n    let mut prof_ctl = jemalloc_pprof::PROF_CTL\n        .as_ref()\n        .ok_or(ApiError::InternalServerError(anyhow!(\n            \"heap profiling not enabled\"\n        )))?\n        .lock()\n        .await;\n    if !prof_ctl.activated() {\n        return Err(ApiError::InternalServerError(anyhow!(\n            \"heap profiling not enabled\"\n        )));\n    }\n\n    // Take and return the profile.\n    match format {\n        Format::Jemalloc => {\n            // NB: file is an open handle to a tempfile that's already deleted.\n            let file = tokio::task::spawn_blocking(move || prof_ctl.dump())\n                .await\n                .map_err(|join_err| ApiError::InternalServerError(join_err.into()))?\n                .map_err(ApiError::InternalServerError)?;","sourceCodeStart":465,"sourceCodeEnd":501,"githubUrl":"https://github.com/neondatabase/neon/blob/8f60b04da47ffefe0e52bda2440134b42874eb75/libs/http-utils/src/endpoint.rs#L465-L501","documentation":"Returned as HTTP 500 InternalServerError by profile_heap_handler in neon's http-utils when jemalloc_pprof::PROF_CTL is None, i.e. the binary was built without jemalloc heap-profiling support compiled in (the jemalloc_pprof feature that initializes the global PROF_CTL static never ran). The endpoint exists on every http-utils server, but the capability is compile-time optional, so requesting /profile/heap on a build without it fails at the handle-lookup step.","triggerScenarios":"GET or POST /profile/heap on a neon service binary compiled without jemalloc profiling enabled; PROF_CTL.as_ref() evaluates to None and the handler immediately returns this 500 before inspecting any parameters.","commonSituations":"Debug builds or production binaries built with default features; deploying a binary compiled on a toolchain/platform where jemalloc (and its prof feature) is not enabled; expecting heap profiles because the docs describe the endpoint without noting the build flag.","solutions":["Rebuild/redeploy the service with jemalloc heap profiling enabled (the jemalloc_pprof PROF_CTL must be initialized at startup)","Use a build where the service links jemalloc with opt.prof:true so PROF_CTL is Some","If you cannot rebuild, fall back to OS-level tooling (e.g. pmap, jemalloc's MALLCTL via a profiler-enabled build) or CPU profiles via /profile/cpu"],"exampleFix":"# before\nneon_pageserver ... # built without jemalloc profiling; /profile/heap -> 500\n\n# after\n# build with jemalloc profiling feature enabled, then:\ncurl 'http://localhost:9898/profile/heap?format=pprof'","handlingStrategy":"type-guard","validationCode":"# Probe capability before wiring continuous heap profiling:\nif ! curl -sf http://localhost:9898/profile/heap -o /dev/null; then\n  echo \"binary lacks jemalloc profiling support; rebuild with the jemalloc_pprof feature\"\nfi","typeGuard":"// In Rust, gate the endpoint registration on the capability:\nif jemalloc_pprof::PROF_CTL.as_ref().is_some() {\n    router.get(\"/profile/heap\", profile_heap_handler);\n}","tryCatchPattern":null,"preventionTips":["Build binaries for profiling use with jemalloc profiling enabled","Capability-check /profile/heap once at deploy time rather than at each scrape","Keep separate debug/profiling and production build profiles"],"tags":["neon","http-utils","profiling","jemalloc","build-features","heap-profile"],"backgroundTag":"feature-not-compiled-in","analyzedSha":"8f60b04da47ffefe0e52bda2440134b42874eb75","analyzedAt":"2026-08-16T23:39:28.135Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}