scope: disallow copying scopes to prevent double close of scopes#565
scope: disallow copying scopes to prevent double close of scopes#565legendecas wants to merge 1 commit intonodejs:masterfrom
Conversation
NickNaso
left a comment
There was a problem hiding this comment.
I think that this should prevent runtime error in case of double close. @legendecas Am I right?
Yes, Though I've found that return statuses of napi_close_*_scope have been ignored 🤔 https://github.com/nodejs/node-addon-api/blob/master/napi-inl.h#L3475. Are these behavior expected? |
|
@legendecas I believe the reason for that is that, if C++ exceptions are turned on, one would be throwing a C++ exception from a destructor which by my understanding is a big no-no. |
|
Since no exceptions were expected to be thrown in the destructor, I'd think to disallow copying of scopes should be an intuitive approach. What do you think? @gabrielschulhof |
|
This would be a breaking change. While we've not said that will never happen for node-addon-api, we have chosen to avoid those in all cases before. I think we'd want to have a really good reason to introduce a breaking change and I'm not sure it's going to be worth it in this case. |
mhdawson
left a comment
There was a problem hiding this comment.
Marking as request changes until there is a discussion on whether making a breaking change is what we want to do.
Technically it would depend on platforms and possibly crash on double closing a handle scope -- since in node core So I'd wonder there would hardly be possible any use case in the wild. But yes, it is a breaking change. |
|
Append: node core has a pre-condition of deleting the |
|
PPS: still, I could produce the crash with the following snippet: Value doubleCloseScopeNapi(const CallbackInfo& info) {
Env env = info.Env();
HandleScope scope(env);
HandleScope scope2(env);
HandleScope scope3 = scope2;
return env.Undefined();
}Output: |
|
Discussed in meeting today:
Consensus is we should we remove them. |
|
We did discuss and this should land as a SemVer major even though it should not affect any existing code. |
|
Landed as 34c11cf |
Early detect and prevent unexpected crashing on closing an already closed handle scope.
npm testpassed