Skip to content

Commit f6bbe2d

Browse files
committed
Safer approach
1 parent d242e7d commit f6bbe2d

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ ENTRYPOINT [ "solvers" ]
6060

6161
# Extract Binary
6262
FROM intermediate
63+
64+
# Configure jemalloc profiling (only affects services built with jemalloc-profiling feature)
65+
# prof:true - Enable profiling
66+
# prof_active:true - Start profiling immediately
67+
# lg_prof_sample:19 - Sample every 2^19 bytes (~524KB)
68+
ENV MALLOC_CONF="prof:true,prof_active:true,lg_prof_sample:19"
69+
6370
RUN apt-get update && \
6471
apt-get install -y build-essential cmake git zlib1g-dev libelf-dev libdw-dev libboost-dev libboost-iostreams-dev libboost-program-options-dev libboost-system-dev libboost-filesystem-dev libunwind-dev libzstd-dev git netcat-openbsd
6572
RUN git clone https://invent.kde.org/sdk/heaptrack.git /heaptrack && \

crates/observe/src/heap_dump_handler.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,17 @@ async fn generate_and_stream_dump(socket: &mut UnixStream) {
8989
tracing::info!("generating heap dump via jemalloc_pprof");
9090

9191
// Access the global profiling controller
92-
let prof_ctl = match jemalloc_pprof::PROF_CTL.as_ref() {
93-
Some(ctl) => ctl,
94-
None => {
92+
// Catch panic if jemalloc profiling is not available
93+
let prof_ctl = match std::panic::catch_unwind(|| jemalloc_pprof::PROF_CTL.as_ref()) {
94+
Ok(Some(ctl)) => ctl,
95+
Ok(None) => {
9596
tracing::error!("jemalloc profiling not initialized");
9697
return;
9798
}
99+
Err(_) => {
100+
tracing::error!("jemalloc profiling not available - service not built with jemalloc-profiling feature or allocator not configured");
101+
return;
102+
}
98103
};
99104

100105
let mut prof_ctl = prof_ctl.lock().await;

0 commit comments

Comments
 (0)