Skip to content

Commit

Permalink
fixup! src: do proper error checking in AsyncWrap::MakeCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
addaleax committed Jun 13, 2018
1 parent c395973 commit fa46748
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/handle_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ class HandleWrap : public AsyncWrap {
void MarkAsInitialized();
void MarkAsUninitialized();

inline bool IsHandleClosing() const {
return state_ == kClosing || state_ == kClosed;
}

private:
friend class Environment;
friend void GetActiveHandles(const v8::FunctionCallbackInfo<v8::Value>&);
Expand Down
12 changes: 12 additions & 0 deletions src/node_messaging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,21 @@ uv_async_t* MessagePort::async() {
}

void MessagePort::TriggerAsync() {
if (IsHandleClosing()) return;
CHECK_EQ(uv_async_send(async()), 0);
}

void MessagePort::Close(v8::Local<v8::Value> close_callback) {
if (data_) {
// Wrap this call with accessing the mutex, so that TriggerAsync()
// can check IsHandleClosing() without race conditions.
Mutex::ScopedLock sibling_lock(data_->mutex_);
HandleWrap::Close(close_callback);
} else {
HandleWrap::Close(close_callback);
}
}

void MessagePort::New(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
if (!args.IsConstructCall()) {
Expand Down
2 changes: 2 additions & 0 deletions src/node_messaging.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ class MessagePort : public HandleWrap {
std::unique_ptr<MessagePortData> Detach();

bool IsSiblingClosed() const;
void Close(
v8::Local<v8::Value> close_callback = v8::Local<v8::Value>()) override;

size_t self_size() const override;

Expand Down

0 comments on commit fa46748

Please sign in to comment.