mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: destroy parent port backend when JS env exits (#46496)
* fix: destroy parent port backend when JS env exits Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> * fix: close parent port before destroying Co-authored-by: deepak1556 <hop2deep@gmail.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by: deepak1556 <hop2deep@gmail.com>
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user