-
Notifications
You must be signed in to change notification settings - Fork 85
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
fflate and Node v22 #227
Comments
That's a bit concerning - I'll have a look tomorrow. |
OK, this is just a bug in the test-bench because I was trying to transfer a Is there a larger issue you're running into with Node v22 that causes the hanging behavior you've described? |
We use this in the MetaMask Extension's build system and discovered it when attempting to update to Node v22 (our issue: MetaMask/metamask-extension#28368) We use it here: https://github.com/MetaMask/metamask-extension/blob/39528b02100a6003f412bbef5e0b560002c945bc/development/webpack/utils/plugins/ManifestPlugin/index.ts#L48-L63 (ignore the "use a copy of the Buffer" comment, the Buffer copy operation is done elsewhere) |
I'm not sure if it helps, but if you add this test to your suite, it passes on Node 20 but fails on Node 22. It also passes if you use
|
@101arrowz any ideas how to solve this? |
@davidmurdoch @HowardBraham BTW, the change of |
In Node.js instances of
|
The real issue here is with the tests that Node.js has decided to disable the old behavior of silently allowing attempted transfers of buffers that are views into the global My assumption was accurate until Node.js version 22; now however, Node throws an error when you attempt to transfer a pooled This issue does not affect any synchronous functions because no data needs to be transferred between threads. It also doesn't affect most of the asynchronous functions because they do not assume consume the input by default (i.e. they copy memory to the other thread instead of transferring). However, it does affect the streaming asynchronous APIs, including What I'm planning to do is special-case the Node.js worker implementation to skip transferring buffers that are pooled altogether, which will essentially restore the old functionality. For now, you can work around the issue by copying all buffers before passing them into a streaming asynchronous API: const myZipDeflate = new fflate.AsyncZipDeflate(...);.
const data = fs.readFileSync('hello.txt');
// instead of this:
// myZipDeflate.push(data)
// do this:
myZipDeflate.push(new Uint8Array(data));
// or this, if you want to save some copies:
const { isMarkedAsUntransferable } = require('worker_threads');
let transferableBuffer = isMarkedAsUntransferable(data) ? new Uint8Array(data) : data;
myZipDeflate.push(transferableBuffer); (BTW: the reason "converting" a |
…rrays before zipping See: 101arrowz/fflate#227 (comment)
…rrays before zipping See: 101arrowz/fflate#227 (comment)
…t8Array`s before zipping (#29177) Use a copy of the Buffer via `Buffer.from(asset)`, as Zip will *consume* it, which breaks things if we are compiling for multiple browsers at once. `Buffer.from` uses the internal pool, so it's superior to `new Uint8Array` if we don't need to pass it off to a worker thread. Additionally, in Node.js 22+ a Buffer marked as "Untransferable" (like ours) can't be passed to a worker, which `AsyncZipDeflate` uses. See: 101arrowz/fflate#227 (comment) This can probably be simplified to `zipFile.push(Buffer.from(asset), true);` if the above issue is resolved. This fix should hopefully unblock #28368 <!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. ## **Description** <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/29177?quickstart=1) ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** ### **Before** ### **After** ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. -->
…t8Array`s before zipping (#29177) Use a copy of the Buffer via `Buffer.from(asset)`, as Zip will *consume* it, which breaks things if we are compiling for multiple browsers at once. `Buffer.from` uses the internal pool, so it's superior to `new Uint8Array` if we don't need to pass it off to a worker thread. Additionally, in Node.js 22+ a Buffer marked as "Untransferable" (like ours) can't be passed to a worker, which `AsyncZipDeflate` uses. See: 101arrowz/fflate#227 (comment) This can probably be simplified to `zipFile.push(Buffer.from(asset), true);` if the above issue is resolved. This fix should hopefully unblock #28368 <!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. ## **Description** <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/29177?quickstart=1) ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** ### **Before** ### **After** ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. -->
## **Description** Node LTS just moved to 22, let's start using it. Keeping this as-is in package.json for now: `"node": ">= 20",` Was previously blocked by 101arrowz/fflate#227 Just merged this and now it's unblocked #29177 [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28368?quickstart=1) <!--## **Related issues** ## **Manual testing steps** ## **Screenshots/Recordings** ### **Before** ### **After** ## **Pre-merge author checklist** ## **Pre-merge reviewer checklist**-->
## **Description** Node LTS just moved to 22, let's start using it. Keeping this as-is in package.json for now: `"node": ">= 20",` Was previously blocked by 101arrowz/fflate#227 Just merged this and now it's unblocked #29177 [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28368?quickstart=1) <!--## **Related issues** ## **Manual testing steps** ## **Screenshots/Recordings** ### **Before** ### **After** ## **Pre-merge author checklist** ## **Pre-merge reviewer checklist**-->
How to reproduce
The
fflate
library appears to be incompatible with Node v22, now the LTS version.It fails and hangs in our application.
The problem
Running the test suite in Node v22 produces this result:
The text was updated successfully, but these errors were encountered: