Skip to content

Can I use --experimental-permission in new worker_threads.Worder's execArgv? #1043

Closed

Description

@LongTengDao

The doc said that's "process-based permission". But it's actually based on execArgv, does it mean that, it can also be used for create worker by design (and "process-based" is a only provisional loose wording used to emphasize the difference from "module-based")?

Activity

  1. RafaelGSS commented on Jul 6, 2023

    @RafaelGSS
    Member

    What do you mean by execArgv? If you want to create a worker when using the permission model, you should ensure to pass --experimental-permission + all the permissions the worker needs. We don't do it by default, it's up to the developer.

  2. LongTengDao commented on Jul 9, 2023

    @LongTengDao
    Author

    So actually --experimental-permission is not a "process-based permission", but "thread-based permission"?

  3. RafaelGSS commented on Jul 10, 2023

    @RafaelGSS
    Member

    You can call main thread-based permission, yeah.

  4. RafaelGSS commented on Jul 10, 2023

    @RafaelGSS
    Member

    What's your use case?

  5. LongTengDao commented on Jul 11, 2023

    @LongTengDao
    Author

    You can call main thread-based permission, yeah.

    What about other threads?

    What's your use case?

    Thank you for your attentive.

    I'm making a sandbox util to run code and keep them away from disk.

    There are many codes to run, so if I can use new worker_threads.Worker 100 times instead of child_process.fork 100 times, the cost will be less.

    Currently, my code looks like sample 1 because the docs said it's "process-based permission":

    function fn (id) {
        return child_process.fork(`/path/to/${id}.js`, [], {
            execArgv: [ `--experimental-permission`, `--allow-fs-read=/path/to/${id}.js` ]
        });
    }

    And if actually it's "thread-based permission", I want to make it looking like sample 2:

    function fn (id) {
        return new worker_threads.Worker(`/path/to/${id}.js`, {
            execArgv: [ `--experimental-permission`, `--allow-fs-read=/path/to/${id}.js` ]
        });
    }
  6. RafaelGSS commented on Jul 11, 2023

    @RafaelGSS
    Member

    Well, if you pass the correct arguments to the new Worker you should be fine, right? Unless you need to use the --experimental-permission in the main thread, in that case, you need to pass --allow-worker and make sure to load code that wouldn't bypass it (in the main-thread).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions