Uh oh!
There was an error while loading. Please reload this page.
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 into
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? |
gabrielschulhof
commented
Oct 15, 2019
@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. |
legendecas
commented
Oct 15, 2019
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 |
mhdawson
commented
Oct 17, 2019
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.
legendecas
commented
Oct 17, 2019
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. |
legendecas
commented
Oct 17, 2019
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: |
mhdawson
commented
Oct 21, 2019
Discussed in meeting today:
Consensus is we should we remove them. |
mhdawson
commented
Oct 21, 2019
We did discuss and this should land as a SemVer major even though it should not affect any existing code. |
mhdawson
commented
Oct 23, 2019
Landed as 34c11cf |
Early detect and prevent unexpected crashing on closing an already closed handle scope.
npm testpassed