-
-
Notifications
You must be signed in to change notification settings - Fork 323
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
fix: ensure transferred ArrayBuffer are Transferable #6251
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## unstable #6251 +/- ##
=========================================
Coverage 80.31% 80.31%
=========================================
Files 202 202
Lines 19543 19543
Branches 1169 1169
=========================================
Hits 15695 15695
Misses 3820 3820
Partials 28 28 |
Performance Report✔️ no performance regression detected Full benchmark results
|
const isMarkedAsUntransferable = unknownWorker["isMarkedAsUntransferable"]; | ||
// Can be updated to direct access once minimal version of node is 21 | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call | ||
if (isMarkedAsUntransferable && isMarkedAsUntransferable(buffer)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the buffer always untransferable or why do we need this check? Based on nodejs/node#47604 it would previously (node 20) just silently copy the buffer while with node 21 it throws an error. The problem seems to be related to @chainsafe/bls-keystore and how the keystore buffer is created.
Upgrading @chainsafe/bls-keystore fixes the issue for me since with v3 it uses Unit8Array instead of Buffer. Will do some performance testing with new version and open PR for that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, it might not be transferred at all with node20.
If the new @chainsafe/bls-keystore
offers equivalent or better perf that's definitely the better option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you try #6253 on your machine? At least on linux there are no issues running unit tests on node 21
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can confirm that it works on osx with node 21
Closing this PR for now since #6253 resolved the issue |
Motivation
test:unit
do not pass on nodejs starting version 21 due to a change inArrayBuffer
transferabilityDescription
Node version 21 introduces changes to the way ArrayBuffer transferability are dealt with. Specifically some of current usage now is not transferable anymore and breaks usage.
To deal with this, a new API has been introduced in node 21 to detect if an object has been marked as not transferable. This API is used (when available) to do a copy of the underlying buffer instead of directly transferring it.
Performance in this case is still assumed to be better than going through full (de)/serialization.