Skip to content

Commit ce48936

Browse files
addaleaxtargos
authored andcommitted
src: plug trace file file descriptor leak
Close existing file descriptors before overriding the field with new ones. Also, use `nullptr` as the loop for these synchronous operations, since they do not run on the same thread as the `uv_run()` call for the previously used loop. PR-URL: #21867 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Eugene Ostroukhov <[email protected]> Reviewed-By: Ali Ijaz Sheikh <[email protected]>
1 parent 89e2302 commit ce48936

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/tracing/node_trace_writer.cc

+7-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ NodeTraceWriter::~NodeTraceWriter() {
5353
uv_fs_t req;
5454
int err;
5555
if (fd_ != -1) {
56-
err = uv_fs_close(tracing_loop_, &req, fd_, nullptr);
56+
err = uv_fs_close(nullptr, &req, fd_, nullptr);
5757
CHECK_EQ(err, 0);
5858
uv_fs_req_cleanup(&req);
5959
}
@@ -84,7 +84,12 @@ void NodeTraceWriter::OpenNewFileForStreaming() {
8484
replace_substring(&filepath, "${pid}", std::to_string(uv_os_getpid()));
8585
replace_substring(&filepath, "${rotation}", std::to_string(file_num_));
8686

87-
fd_ = uv_fs_open(tracing_loop_, &req, filepath.c_str(),
87+
if (fd_ != -1) {
88+
CHECK_EQ(uv_fs_close(nullptr, &req, fd_, nullptr), 0);
89+
uv_fs_req_cleanup(&req);
90+
}
91+
92+
fd_ = uv_fs_open(nullptr, &req, filepath.c_str(),
8893
O_CREAT | O_WRONLY | O_TRUNC, 0644, nullptr);
8994
uv_fs_req_cleanup(&req);
9095
if (fd_ < 0) {

0 commit comments

Comments
 (0)