Skip to content

Commit 51a5af2

Browse files
server: Fix heap profile temp file is dropped before reading (tikv#16171)
close tikv#16169 Fix heap profile temp file is dropped before reading Signed-off-by: Connor1996 <[email protected]> Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
1 parent 95da026 commit 51a5af2

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/server/status_server/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,11 @@ where
136136
let use_jeprof = query_pairs.get("jeprof").map(|x| x.as_ref()) == Some("true");
137137

138138
let result = {
139-
let path = match dump_one_heap_profile() {
140-
Ok(path) => path,
139+
let file = match dump_one_heap_profile() {
140+
Ok(file) => file,
141141
Err(e) => return Ok(make_response(StatusCode::INTERNAL_SERVER_ERROR, e)),
142142
};
143+
let path = file.path();
143144
if use_jeprof {
144145
jeprof_heap_profile(path.to_str().unwrap())
145146
} else {
@@ -1561,7 +1562,6 @@ mod tests {
15611562

15621563
#[cfg(feature = "mem-profiling")]
15631564
#[test]
1564-
#[ignore]
15651565
fn test_pprof_heap_service() {
15661566
let mut status_server = StatusServer::new(
15671567
1,

src/server/status_server/profile.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
use std::{
33
fs::File,
44
io::{Read, Write},
5-
path::PathBuf,
65
pin::Pin,
76
process::{Command, Stdio},
87
sync::Mutex,
@@ -83,11 +82,11 @@ impl<I, T> Future for ProfileRunner<I, T> {
8382
}
8483

8584
/// Trigger a heap profile and return the content.
86-
pub fn dump_one_heap_profile() -> Result<PathBuf, String> {
85+
pub fn dump_one_heap_profile() -> Result<NamedTempFile, String> {
8786
let f = NamedTempFile::new().map_err(|e| format!("create tmp file fail: {}", e))?;
8887
let path = f.path();
8988
dump_prof(path.to_str().unwrap()).map_err(|e| format!("dump_prof: {}", e))?;
90-
Ok(path.to_owned())
89+
Ok(f)
9190
}
9291

9392
/// Trigger one cpu profile.

0 commit comments

Comments
 (0)