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

Transfered (PostMessaged) disk- blob's aren't readable #47334

Closed
jimmywarting opened this issue Mar 31, 2023 · 1 comment
Closed

Transfered (PostMessaged) disk- blob's aren't readable #47334

jimmywarting opened this issue Mar 31, 2023 · 1 comment
Labels
fs Issues and PRs related to the fs subsystem / file system. worker Issues and PRs related to Worker support.

Comments

@jimmywarting
Copy link

jimmywarting commented Mar 31, 2023

I notice that blobs transfered over workers aren't readable at all.

  • it only applies to blobs coming from fs.openAsBlob
  • in-memory constructed blobs works fine.

mini repro:

import { Worker } from 'worker_threads'
const worker = new Worker('./worker.js')
worker.once('message', blob => {
  // worker.terminate() // Should be fine to do this as well
  blob.text()
})
// worker.js
import { parentPort } from 'node:worker_threads'
import { openAsBlob } from 'node:fs'

const blob = await openAsBlob(import.meta.url.slice(7)) // file:// doesn't work
parentPort.postMessage(blob)

I would assume that if you also closed the worker it would still work just fine to read the blob, even if it came from another thread...

originally posted by @jimmywarting in #45258 (comment)

maybe also worth trying out to write a test that also use MessageChannel?
...haven't tested if MessageChannel works or not.

@debadree25 debadree25 added fs Issues and PRs related to the fs subsystem / file system. worker Issues and PRs related to Worker support. labels Mar 31, 2023
@ronag
Copy link
Member

ronag commented Apr 1, 2023

@jasnell

jasnell added a commit to jasnell/node that referenced this issue Apr 15, 2023
Disallow cloning of file-backed Blobs. If necessary, we can enable
this later but for now we disable it. The reason is because the
underlying FdEntry ends up bound to the Environment/Realm under
which is was created and transfering across worker threads ends up
failing.

Fixes: nodejs#47334
targos pushed a commit that referenced this issue May 2, 2023
Disallow cloning of file-backed Blobs. If necessary, we can enable
this later but for now we disable it. The reason is because the
underlying FdEntry ends up bound to the Environment/Realm under
which is was created and transfering across worker threads ends up
failing.

Fixes: #47334
PR-URL: #47574
Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system. worker Issues and PRs related to Worker support.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants