Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid using deprecated Nan APIs #234

Merged
merged 1 commit into from
Apr 3, 2018

Conversation

ofrobots
Copy link
Contributor

WIP, but opening early to get early feedback, and to kick off the CI. I intend to revert the -Wno-deprecated-declarations removal before this lands.

Starting with Nan 2.9.x certain Nan::Callback::Call APIs are
deprecated. Instead there are mechanisms in place that allow native
modules to preserve async context across async calls.

@thelinuxfoundation
Copy link

Thank you for your pull request. Before we can look at your contribution, we need to ensure all contributors are covered by a Contributor License Agreement.

After the following items are addressed, please respond with a new comment here, and the automated system will re-verify.

Regards,
CLA GitHub bot

@@ -252,6 +253,7 @@ NAN_METHOD(SetDefaultLoggerCallback) {
grpc_logger_state.logger_set = true;
}
grpc_logger_state.callback = new Nan::Callback(info[0].As<v8::Function>());
grpc_logger_state.async_resource = new Nan::AsyncResource("grpc:logger");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't find a delete of grpc_logger_state.callback, but I didn't look too hard either. Wherever we free one, we should free the other.

@@ -318,8 +318,9 @@ NAN_METHOD(Server::TryShutdown) {
Server *server = ObjectWrap::Unwrap<Server>(info.This());
if (server->wrapped_server == NULL) {
// Server is already shut down. Call callback immediately.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that this looks like an instance of Zalgo. Its an edge case though.

@ofrobots
Copy link
Contributor Author

Hello @thelinuxfoundation bot. Please re-verify.

Copy link
Member

@murgatroid99 murgatroid99 left a comment

Choose a reason for hiding this comment

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

In general, are the AsyncResource names supposed to have any semantic meaning at the JS level?

@@ -245,11 +245,10 @@ int plugin_get_metadata(
grpc_metadata creds_md[GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX],
size_t *num_creds_md, grpc_status_code *status,
const char **error_details) {
HandleScope scope;
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need a HandleScope here because this function doesn't call any Node APIs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually the AsyncResource constructor allocates a resource object if one is not passed in. Arguably this could be fixed in Nan instead, but for now, this is the API we have.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fix in Nan: nodejs/nan#757 which will take some time to review / land / release. For now let's use a HandleScope ourselves.

@@ -98,7 +98,7 @@ class Op {
};

typedef std::vector<unique_ptr<Op>> OpVec;
struct tag {
struct tag : public Nan::AsyncResource {
Copy link
Member

Choose a reason for hiding this comment

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

Why have tag inherit from Nan::AsyncResource, instead of just having a Nan::AsyncResource member?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Memory management is easier. No need to explicitly delete tag->async_resource. I don't have strong feelings though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Other reason: tag represents an async operation, so it makes sense for it to be a subclass of AsyncResource.

Copy link
Member

Choose a reason for hiding this comment

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

We don't explicitly delete any of the members. They get deleted by default when the tag object is deleted. And subclassing merely for the purpose of categorization isn't really compelling to me, so I would prefer to use composition here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Composition it is.

@ofrobots
Copy link
Contributor Author

In general, are the AsyncResource names supposed to have any semantic meaning at the JS level?

Documented here. These represent the type of asynchronous operation that caused an async hop. This module introduces async hops of its own via direct usage of the uv event loops. The specified type string will be provided to any debug or diagnostic tool that is monitoring async execution via async_hooks. Ultimately this would be provided to the user where they would be able to distinguish async hops due to timers, net, etc. vs. gRPC.

@ofrobots
Copy link
Contributor Author

@murgatroid99 I am unable to reproduce the test failures locally. Any ideas?

@murgatroid99
Copy link
Member

I made some changes in #248 that touch the same code that this PR touches, and I think that PR also likely fixed the crashes you are seeing here. So if you could merge from master, I think you can get this change to work.

Starting with Nan 2.9.x certain Nan::Callback::Call APIs are
deprecated. Instead there are mechanisms in place that allow native
modules to preserve async context across async calls.
@murgatroid99 murgatroid99 merged commit 0cd71d9 into grpc:master Apr 3, 2018
@ofrobots ofrobots deleted the nan-callback branch April 4, 2018 00:15
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants