Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Fixes problems associated with node 10 and NAN#14847

Merged
flippmoke merged 3 commits into
masterfrom
node10_support
Jun 26, 2019
Merged

Fixes problems associated with node 10 and NAN#14847
flippmoke merged 3 commits into
masterfrom
node10_support

Conversation

@flippmoke
Copy link
Copy Markdown
Member

Might solve #12252

@@ -1244,20 +1246,19 @@ std::unique_ptr<mbgl::AsyncRequest> NodeFileSource::request(const mbgl::Resource
// *this while we're still executing code.
nodeMap->handle();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it is not part of this PR, but how is this holding the reference if we don't assign it to anything?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea what this line does at all.

struct NodeAsyncRequest : public mbgl::AsyncRequest {
NodeAsyncRequest();
~NodeAsyncRequest() override;
NodeRequest* request;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: default to nullptr

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (request) {
// Remove the callback function because the AsyncRequest was
// canceled and we are no longer interested in the result.
request->callback = {};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a request->cancel() would be a cleaner interface

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a MBGL_VERIFY_THREAD to this object? We need to make sure it lives on the main thread.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lifetime of this request object is managed by the unique_ptr that is returned here I thought - https://github.com/mapbox/mapbox-gl-native/blob/node10_support/platform/node/src/node_map.cpp#L1240

auto callback = std::move(request->callback);
request->callback = {};
if (!callback) {
request->unref();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make this code safer, does it work if you create a handle and unref a the beginning of the code? So when the handle goes out of scope we no longer have refs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps my suggestion is overkill :-)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure how you would want this done honestly, could you say more if you want to change this?

@@ -52,7 +58,9 @@ void NodeRequest::HandleCallback(const Nan::FunctionCallbackInfo<v8::Value>& inf

// Move out of the object so callback() can only be fired once.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I think it will make the refcounter negative on double invocation.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what you mean by this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we call the callback twice by mistake on the Javascript side...

Nan::AsyncResource res("mbgl:execute");
res.runInAsyncScope(Nan::To<v8::Object>(target->handle()->GetInternalField(1)).ToLocalChecked(), "request", 1, argv);
void NodeRequest::unref() {
Nan::HandleScope scope;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this scope needed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it is needed because asyncResource is a resource managed by node and we need to make sure that its removed as well from the memory managed by node.

@ian29
Copy link
Copy Markdown

ian29 commented Jun 21, 2019

@flippmoke @tmpsantos what are next steps here?

@@ -52,7 +58,9 @@ void NodeRequest::HandleCallback(const Nan::FunctionCallbackInfo<v8::Value>& inf

// Move out of the object so callback() can only be fired once.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we call the callback twice by mistake on the Javascript side...

@tmpsantos
Copy link
Copy Markdown
Contributor

@flippmoke @tmpsantos what are next steps here?

Good to merge IMO.

@flippmoke
Copy link
Copy Markdown
Member Author

@tmpsantos not sure why the status hasn't passed here?

@tobrun
Copy link
Copy Markdown
Member

tobrun commented Jun 26, 2019

@tmpsantos not sure why the status hasn't passed here?

We recently added 2 new CI bots for running render test.
Rebasing on master/foce pushing will make the bots run.

@flippmoke flippmoke merged commit a16c67d into master Jun 26, 2019
@flippmoke flippmoke deleted the node10_support branch June 26, 2019 18:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Node.js node-mapbox-gl-native

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants