Skip to content

WASI stdio (stdin, stdout) API not very useful #52614

Description

@Timmmm

What is the problem this feature will solve?

Currently the WASI API only lets you give file descriptors for stdin, stdout and stderr. That's not very useful. In most cases I want to interact with these streams which doesn't seem possible - at least not without a ton of platform specific work - with just file descriptors.

What is the feature you are proposing to solve the problem?

You should be able to pass ReadableStream and WritableStream instead. You can do this when spawning subprocesses.

What alternatives have you considered?

Slightly ludicrously, spawning a new child process that just starts the WASI module and does nothing else seems to be the most reasonable workaround currently, though I haven't tried it.

Activity

  1. avivkeller commented on Apr 20, 2024

    @avivkeller
    Member

    Hi! Thanks for the feature request! Could you possible provide more context?

    It'd be really helpful if you could give us a comparison of the current features vs the proposed ones.

    Thank you!

  2. added
    wasiIssues and PRs related to the WebAssembly System Interface.
    on Apr 20, 2024
  3. benjamingr commented on Apr 21, 2024

    @benjamingr
    Member

    @nodejs/wasi

  4. Timmmm commented on Apr 21, 2024

    @Timmmm
    Author

    @redyetidev sure!

    Currently the Node API for WASI is:

    image

    In other words when you start a WASI module, the only option for its stdin/out/err are to give real native file handles. This is quite weird and also inconvenient.

    It's weird because WASI's environment is fully controlled by Node. When it writes to stdin it isn't executing native code that requires a file handle, it's calling some WASM interface function that Node provides. I presume this design is something to do with the big warning about WASI's filesystem access not being sandboxed at all at the moment. Presumably they've done the very simplest thing - just pass through WASI filesystem calls to the OS. So I think this is probably intended to be temporary anyway.

    It's inconvenient because you can't interact with stdin/out/err except via a file descriptor. The only way to do this through Node is by making a file on disk which is not what you would usually want. My use case is a VSCode LSP server; stdio is used for communication.

    Another option would be the pipe() C function, but unfortunately it does not seem to be exposed by Node.

    The API should look more like the API for creating a child process, where you can tell it to "pipe" the streams and then retrieve a stream.Readable/Writable for each.

    Hope that makes sense! The workaround I am considering is just to fork() node, and run a module which only starts my WASI program. I think fork() lets you pipe the stdio streams, but I haven't actually tried it yet.

  5. avivkeller commented on Apr 21, 2024

    @avivkeller
    Member

    Thanks! That makes more sense. I'm not on the WASI team, but the context will help them when they review this.

    Thanks again for your contribution to the community!

  6. mhdawson commented on Apr 25, 2024

    @mhdawson
    Member

    @Timmmm you might want to check out - nodejs/uvwasi#255. I'm not sure how much preview 1 functionality wil be extended in that context so you might want to see if the preview 2 functionality provided via jco is something you want to use instead.

  7. github-actions commented on Oct 23, 2024

    @github-actions
    Contributor

    There has been no activity on this feature request for 5 months. To help maintain relevant open issues, please add the never-stale Issues and PRs exempt from automated stale handling. label or close this issue if it should be closed. If not, the issue will be automatically closed 6 months after the last non-automated comment.
    For more information on how the project manages feature requests, please consult the feature request management document.

  8. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Oct 23, 2024
  9. github-actions commented on Nov 22, 2024

    @github-actions
    Contributor

    There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.

    For more information on how the project manages feature requests, please consult the feature request management document.

  10. Timmmm commented on Nov 22, 2024

    @Timmmm
    Author

    Please can someone reopen this and add the never stale label? Stalebot is awful and I appreciate your attempt to make it less awful with never-stale, but it's not very useful if I don't actually have permission to reopen the issue or add that label is it?

  11. added
    never-staleIssues and PRs exempt from automated stale handling.
    on Nov 22, 2024
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

    feature requestIssues requesting new Node.js features.never-staleIssues and PRs exempt from automated stale handling.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.wasiIssues and PRs related to the WebAssembly System Interface.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions