fix: destroy parent port backend when JS env exits (#46437)
* fix: destroy parent port backend when JS env exits * fix: close parent port before destroying --------- Co-authored-by: deepak1556 <hop2deep@gmail.com>
This commit is contained in:
parent
e81e3acd2d
commit
c2ae4afb8f
3 changed files with 8 additions and 3 deletions
|
@ -96,6 +96,7 @@ NodeService::NodeService(
|
|||
NodeService::~NodeService() {
|
||||
if (!node_env_stopped_) {
|
||||
node_env_->set_trace_sync_io(false);
|
||||
ParentPort::GetInstance()->Close();
|
||||
js_env_->DestroyMicrotasksRunner();
|
||||
node::Stop(node_env_.get(), node::StopFlags::kDoNotTerminateIsolate);
|
||||
}
|
||||
|
@ -147,6 +148,7 @@ void NodeService::Initialize(
|
|||
node_env_.get(), [this](node::Environment* env, int exit_code) {
|
||||
// Destroy node platform.
|
||||
env->set_trace_sync_io(false);
|
||||
ParentPort::GetInstance()->Close();
|
||||
js_env_->DestroyMicrotasksRunner();
|
||||
node::Stop(env, node::StopFlags::kDoNotTerminateIsolate);
|
||||
node_env_stopped_ = true;
|
||||
|
|
|
@ -23,8 +23,8 @@ namespace electron {
|
|||
gin::WrapperInfo ParentPort::kWrapperInfo = {gin::kEmbedderNativeGin};
|
||||
|
||||
ParentPort* ParentPort::GetInstance() {
|
||||
static base::NoDestructor<ParentPort> instance;
|
||||
return instance.get();
|
||||
static ParentPort* instance = new ParentPort();
|
||||
return instance;
|
||||
}
|
||||
|
||||
ParentPort::ParentPort() = default;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "gin/wrappable.h"
|
||||
#include "mojo/public/cpp/bindings/connector.h"
|
||||
#include "mojo/public/cpp/bindings/message.h"
|
||||
#include "shell/common/gin_helper/cleaned_up_at_exit.h"
|
||||
#include "third_party/blink/public/common/messaging/message_port_descriptor.h"
|
||||
|
||||
namespace v8 {
|
||||
|
@ -31,6 +32,7 @@ namespace electron {
|
|||
// for the lifetime of a Utility Process which
|
||||
// also means that GC lifecycle is ignored by this class.
|
||||
class ParentPort final : public gin::Wrappable<ParentPort>,
|
||||
public gin_helper::CleanedUpAtExit,
|
||||
private mojo::MessageReceiver {
|
||||
public:
|
||||
static ParentPort* GetInstance();
|
||||
|
@ -49,9 +51,10 @@ class ParentPort final : public gin::Wrappable<ParentPort>,
|
|||
v8::Isolate* isolate) override;
|
||||
const char* GetTypeName() override;
|
||||
|
||||
void Close();
|
||||
|
||||
private:
|
||||
void PostMessage(v8::Local<v8::Value> message_value);
|
||||
void Close();
|
||||
void Start();
|
||||
void Pause();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue