Skip to content
Snippets Groups Projects
Unverified Commit bec027b5 authored by Shelley Vohr's avatar Shelley Vohr
Browse files

fix: ensure utilityProcess only emits one exit

parent 566c72cd
No related merge requests found
......@@ -7,6 +7,7 @@
#include <map>
#include <utility>
#include "base/debug/stack_trace.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/no_destructor.h"
......@@ -247,12 +248,16 @@ void UtilityProcessWrapper::OnServiceProcessLaunch(
}
void UtilityProcessWrapper::HandleTermination(uint64_t exit_code) {
// HandleTermination is called from multiple callsites,
// we need to ensure we only process it for the first callsite.
if (terminated_)
return;
terminated_ = true;
if (pid_ != base::kNullProcessId)
GetAllUtilityProcessWrappers().Remove(pid_);
CloseConnectorPort();
EmitWithoutEvent("exit", exit_code);
Unpin();
}
......@@ -269,7 +274,6 @@ void UtilityProcessWrapper::OnServiceProcessTerminatedNormally(
if (!info.IsService<node::mojom::NodeService>() ||
info.GetProcess().Pid() != pid_)
return;
HandleTermination(info.exit_code());
}
......@@ -278,7 +282,6 @@ void UtilityProcessWrapper::OnServiceProcessCrashed(
if (!info.IsService<node::mojom::NodeService>() ||
info.GetProcess().Pid() != pid_)
return;
HandleTermination(info.exit_code());
}
......@@ -292,13 +295,8 @@ void UtilityProcessWrapper::CloseConnectorPort() {
}
void UtilityProcessWrapper::Shutdown(uint64_t exit_code) {
if (pid_ != base::kNullProcessId)
GetAllUtilityProcessWrappers().Remove(pid_);
node_service_remote_.reset();
CloseConnectorPort();
// Emit 'exit' event
EmitWithoutEvent("exit", exit_code);
Unpin();
HandleTermination(exit_code);
}
void UtilityProcessWrapper::PostMessage(gin::Arguments* args) {
......
......@@ -105,6 +105,7 @@ class UtilityProcessWrapper final
int stdout_read_fd_ = -1;
int stderr_read_fd_ = -1;
bool connector_closed_ = false;
bool terminated_ = false;
std::unique_ptr<mojo::Connector> connector_;
blink::MessagePortDescriptor host_port_;
mojo::Receiver<node::mojom::NodeServiceClient> receiver_{this};
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment