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

node::MakeCallback is dangerous, can you detect misuse and warn? #9245

Closed
@metamatt

Description

@metamatt

This issue springs from TooTallNate/node-weak#35, but the root cause is that node::MakeCallback is dangerous if misused, and it would be nice to prevent its misuse.

By "misuse", I mean: if you have a Handle<Function> in a node addon and you want to call it, you have the choice of calling it directly (Handle<Function>::Call()) or via node::MakeCallback. You should do the former if your addon code was invoked from JS code; you should do the latter if your addon code was invoked directly from libuv as an event callback. This difference, while crucial, is not plainly obvious, and if you get it wrong, the results are really bad (preemption of Javascript code, that breaks Node's entire threadless/concurrency/consistency model).

Note comment TooTallNate/node-weak#36 (comment) from @trevnorris (and the surrounding discussion) saying that MakeCallback should be benign if called unnecessarily, but in my observation, that's not true. So I'm following up on this old discussion with an issue report and demo/repro case (for NodeJS 0.12.0) that shows it's actually (and still) dangerous if called this way.

The repro case is at https://gist.github.com/metamatt/4ce96adbf14de9a97d41.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions