-
-
Notifications
You must be signed in to change notification settings - Fork 472
Closing FileHandle
in addon's Finalize
method
#1648
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
Comments
We discussed in the node-api team meeting today.
|
@mhdawson I'm very thankful for you attention and effort; I tried to follow exactly as the document you mentioned, says; At Handling Errors Without C++ Exceptions it says:
You can see I used As for infos you requested:
|
There's a second problem which I open another issue for it if I should, but since it is just another stupid question I didn't want to bother you more than I do. class filelock : public Napi::ObjectWrap<filelock>
{
public:
//...
static Napi::Value OnCalledAsFunction(const Napi::CallbackInfo& callbackInfo);
//...
}; Method definition: Napi::Value filelock::OnCalledAsFunction(const Napi::CallbackInfo& callbackInfo)
{
std::cerr << "OnCalledAsFunction" << std::endl;
Napi::TypeError::New(callbackInfo.Env(), "filelock constructor cannot be invoked without 'new'").ThrowAsJavaScriptException();
return callbackInfo.Env().Undefined();
} Now if I call the ctor without OnCalledAsFunction
(node:38063) Warning: Closing file descriptor 29 on garbage collection
(Use `node --trace-warnings ...` to show where the warning was created)
(node:38063) [DEP0137] DeprecationWarning: Closing a FileHandle object on garbage collection is deprecated. Please close FileHandle objects explicitly using FileHandle.prototype.close(). In the future, an error will be thrown if a file descriptor is closed during garbage collection. This is the exact same behavior I get as when I don't define export async function create(metadata, body)
{
let metaFileFD;
try { metaFileFD = await open(requestedFile, constants.O_CREAT | constants.O_RDWR, 0o600); }
catch(err){throw err;}
let lock = await filelock(metaFileFD).acquireWriteLock();
} |
I think it is hard for people to understand what the issue is when conflating multiple issues together. Would you mind clarifying what the issue is and what you expect from node-addon-api? Thank you very much! |
@legendecas |
From our discussion in the team meeting today we are still thinking its likely a problem in the addon itself. Could you run with valgrind to see if it helps point out where memory might be being used after it has been freed? Some info on how to do that is in https://github.com/nodejs/node/blob/main/doc/contributing/investigating-native-memory-leaks.md |
@mhdawson |
I have a simple addon accepting a
FileHandle
object in its constructor:And the Finalize method:
Running this code after I saved Persistent ref. to
FileHandle
, works ok with VScode JS debugger, but causing core dump when ran in normal terminal!Secondly: When C++ exceptions aren't enabled (cmake-js default) how should I catch errors? not
try-catch
norIsExceptionPending
works in the above code and I getterminate called after throwing an instance of 'Napi::Error'
.Third: Is calling
close
safe in a basic Finalizer? As it worked just the same as above! What APIs considered safe and not accessing JS heap (I mean is there an easy way to tell if API is accessing heap)?My humblest and greatest regards.
The text was updated successfully, but these errors were encountered: