Repository navigation
fix(fs): copy binary files for each target in initFiles() - #67
Merged
Merged
Conversation
initFiles() built one transfer list from the caller's ArrayBuffers and passed it to every target. The first postMessage() detached the buffers, so with two or more targets the next one threw a DataCloneError after only the first target had received the files. With one target, the caller's buffers ended up detached. The same ArrayBuffer given for two paths also threw a DataCloneError, even with one target, because the transfer list held it twice. As writeFile() does since #61, initFiles() now gives each target its own copy of every binary file and transfers only the copies, so the caller's ArrayBuffers stay usable. broadcast() no longer takes a transfer list, because one list cannot be transferred to more than one target. The JSDoc of FSInitMessage and initFiles() describes the copies.
The README example of initFiles() now passes a binary file as well, and notes that each target gets its own copy, as the writeFile() example does. The API references are regenerated for the JSDoc of FSInitMessage and initFiles().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #63
FileSystemPublisher.initFiles()now gives each target its own copy of every binary file, aswriteFile()does since #61. It works with two or more targets, and the caller'sArrayBuffers stay usable.Cause
initFiles()built one transfer list from the caller'sArrayBuffers and passed it topostMessage()of every target:postMessage()transferred the buffers, which detached them.postMessage()threw aDataCloneError, after only the first target had received the files.Fix
initFiles()copies every binary file withslice(0)and transfers only the copies, aswriteFile()does.broadcast()no longer takes a transfer list, because one list cannot be transferred to more than one target. Targets still receive an empty transfer list, sowriteFile()for text,unlink()andmkdir()post as before.FSInitMessageandinitFiles(), the README example and the API references describe the copies.Also fixed
The same
ArrayBuffergiven for two paths threw aDataCloneError("Transfer list contains duplicate ArrayBuffer") even with one target, because the transfer list held it twice. Each path now gets its own copy.Behavior change
The caller's
ArrayBuffers are no longer transferred. Each target gets one more copy, and the caller keeps its buffers until it drops them. A caller that relied on the transfer to move the memory to a single target now keeps a copy. Usages that worked before keep working.Vrowzer does not call
initFiles(), so its behavior does not change.Not included
writeFile()keeps its current copy-and-transfer behavior.SharedArrayBuffers, as withwriteFile().postMessage()throws partway: the earlier targets keep what they received, as withwriteFile().Tests
publisher.test.ts:MessageChannelport targets, which really transfer buffers, both receive the text and binary files with the same bytes, and the caller's buffer keeps its size and content afterinitFiles()returns.ArrayBuffergiven for two paths reaches a port target under both paths.The four new or changed tests failed before the change: the two port tests with a
DataCloneError, and the mock tests because the caller's buffers were transferred.Validated locally with:
vp run test:unit: 119 files, 1,914 testsvp run test:integration:vrowzer: 67 passed and 1 conditional skip, after rebuilding@vrowzer/fs, because Vrowzer's file methods go throughbroadcast()andwriteFile()initFiles()