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

napi 2.10.3 produces warnings after call Buffer.as_ref() #1401

Closed
doochik opened this issue Dec 19, 2022 · 1 comment
Closed

napi 2.10.3 produces warnings after call Buffer.as_ref() #1401

doochik opened this issue Dec 19, 2022 · 1 comment
Assignees

Comments

@doochik
Copy link

doochik commented Dec 19, 2022

Seems to be from ef5dffc

Steps to reproduce

  1. build https://github.com/fengkx/zstd-napi-rs with latest napi@2.10.3
  2. run node simple-test.js
  3. Get warnings
% node  simple-test.js                                                                      
(node:62616) [DEP0168] DeprecationWarning: Uncaught N-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=trueto handle those exceptions properly.
(Use `node --trace-deprecation ...` to show where the warning was created)
(node:62616) [DEP0168] DeprecationWarning: Uncaught N-API callback exception detected, please run node with option --force-node-api-uncaught-exceptions-policy=trueto handle those exceptions properly.
Simple test passed

% node --trace-deprecation --force-node-api-uncaught-exceptions-policy=trueto simple-test.js
undefined:0


[Error: Failed to unref Buffer reference in Custom GC] {
  code: 'GenericFailure'
}

Node.js v18.12.1

napi@2.10.2 doesn't produce any warnings

I think that problem is here, but I can't figure out how to fix it.

#[napi]
pub async fn compress(input: Either<String, Buffer>) -> Result<Buffer> {
  let input: &[u8] = match &input {
    Either::A(str) => str.as_bytes(),
    Either::B(buf) => buf.as_ref(),   // <------- this ref
  };
  let mut output = Vec::new();
  let mut encoder = ZstdEncoder::new(&mut output);
  tokio::io::AsyncWriteExt::write_all(&mut encoder, input)
    .await
    .unwrap();
  encoder.shutdown().await?;
  Ok(Buffer::from(output))
}
@Brooooooklyn Brooooooklyn self-assigned this Dec 20, 2022
@Wodann
Copy link
Contributor

Wodann commented Dec 22, 2022

Experiencing the same problem. napi@2.10.2 indeed does not throw the mentioned exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants