Skip to content

Commit 4c9c1bb

Browse files
addaleaxtargos
authored andcommitted
src: fix tracing if cwd or file path is inaccessible
Otherwise this would have crashed the process. In particular, checking the return value of an libuv call against `-1` was invalid to begin with, as libuv uses it to propagate the error code. 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 c101b39 commit 4c9c1bb

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/tracing/node_trace_writer.cc

+7-1
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,13 @@ void NodeTraceWriter::OpenNewFileForStreaming() {
7777

7878
fd_ = uv_fs_open(tracing_loop_, &req, filepath.c_str(),
7979
O_CREAT | O_WRONLY | O_TRUNC, 0644, nullptr);
80-
CHECK_NE(fd_, -1);
8180
uv_fs_req_cleanup(&req);
81+
if (fd_ < 0) {
82+
fprintf(stderr, "Could not open trace file %s: %s\n",
83+
filepath.c_str(),
84+
uv_strerror(fd_));
85+
fd_ = -1;
86+
}
8287
}
8388

8489
void NodeTraceWriter::AppendTraceEvent(TraceObject* trace_event) {
@@ -145,6 +150,7 @@ void NodeTraceWriter::Flush(bool blocking) {
145150
}
146151

147152
void NodeTraceWriter::WriteToFile(std::string&& str, int highest_request_id) {
153+
if (fd_ == -1) return;
148154
WriteRequest* write_req = new WriteRequest();
149155
write_req->str = std::move(str);
150156
write_req->writer = this;

0 commit comments

Comments
 (0)