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

[WASM] Anonymous pipes issue #75394

Closed
adamsitnik opened this issue Sep 10, 2022 · 6 comments
Closed

[WASM] Anonymous pipes issue #75394

adamsitnik opened this issue Sep 10, 2022 · 6 comments
Labels
arch-wasm WebAssembly architecture area-System.IO

Comments

@adamsitnik
Copy link
Member

In dotnet/BenchmarkDotNet#2092 I wanted to use Anonymous Pipes for communication between Host and Benchmark process.

The idea was very simple. The host process (always a .NET console app) creates two anonymous pipes:

using AnonymousPipeServerStream inputFromBenchmark = new AnonymousPipeServerStream(PipeDirection.In, HandleInheritability.Inheritable);
using AnonymousPipeServerStream acknowledgments = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable);

Starts a new process and provides the handles as strings:

string args = benchmarkId.ToArguments(inputFromBenchmark.GetClientHandleAsString(), acknowledgments.GetClientHandleAsString());

Then the benchmark process parses the ids, creates a SafeFileHandle from it and provides it to FileStream that is later used for reading/writing:

private Stream OpenAnonymousPipe(string fileHandle, FileAccess access)
{
    var sfh = new SafeFileHandle(new IntPtr(int.Parse(fileHandle)), ownsHandle: true);
    return new FileStream(sfh, access);
}

It works fine for .NET, .NET Framework on all OSes but not with WASM.

On Linux, I am getting following error when trying to perform first read/write:

Error: Access to the path is denied.
    at $o (/home/adam/projects/performance/artifacts/bin/MicroBenchmarks/Release/net7.0/6030f12e-9262-45b4-8132-240f1ecaa9ea/bin/net7.0/browser-wasm/AppBundle/dotnet.js:5:37754)
    at Ws (/home/adam/projects/performance/artifacts/bin/MicroBenchmarks/Release/net7.0/6030f12e-9262-45b4-8132-240f1ecaa9ea/bin/net7.0/browser-wasm/AppBundle/dotnet.js:5:55546)
    at Object.b.javaScriptExports.call_entry_point (/home/adam/projects/performance/artifacts/bin/MicroBenchmarks/Release/net7.0/6030f12e-9262-45b4-8132-240f1ecaa9ea/bin/net7.0/browser-wasm/AppBundle/dotnet.js:5:58159)
    at Object.Te [as runMain] (/home/adam/projects/performance/artifacts/bin/MicroBenchmarks/Release/net7.0/6030f12e-9262-45b4-8132-240f1ecaa9ea/bin/net7.0/browser-wasm/AppBundle/dotnet.js:5:2713)
    at run (test-main.js:331:50)
Error: Access to the path is denied.
    at $o (/home/adam/projects/performance/artifacts/bin/MicroBenchmarks/Release/net7.0/6030f12e-9262-45b4-8132-240f1ecaa9ea/bin/net7.0/browser-wasm/AppBundle/dotnet.js:5:37754)
    at Ws (/home/adam/projects/performance/artifacts/bin/MicroBenchmarks/Release/net7.0/6030f12e-9262-45b4-8132-240f1ecaa9ea/bin/net7.0/browser-wasm/AppBundle/dotnet.js:5:55546)
    at Object.b.javaScriptExports.call_entry_point (/home/adam/projects/performance/artifacts/bin/MicroBenchmarks/Release/net7.0/6030f12e-9262-45b4-8132-240f1ecaa9ea/bin/net7.0/browser-wasm/AppBundle/dotnet.js:5:58159)
    at Object.Te [as runMain] (/home/adam/projects/performance/artifacts/bin/MicroBenchmarks/Release/net7.0/6030f12e-9262-45b4-8132-240f1ecaa9ea/bin/net7.0/browser-wasm/AppBundle/dotnet.js:5:2713)
    at run (test-main.js:331:50)
WASM EXIT 1

BenchmarkDotNet is using v8 to run the benchmarks (v8 --expose_wasm test-main.js).

@radical @lambdageek @naricc @vargaz Have you ever faced similar issue with WASM or have any idea what could be going wrong?

Can v8 be internally staring another process with no handle inheritance for some kind of sandboxing?
Can Emscripten not support anonymous pipes by design (security?)?

I would really like to get it working and avoid having dedicated code path for WASM.

@adamsitnik adamsitnik added the arch-wasm WebAssembly architecture label Sep 10, 2022
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Sep 10, 2022
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost
Copy link

ghost commented Sep 10, 2022

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

In dotnet/BenchmarkDotNet#2092 I wanted to use Anonymous Pipes for communication between Host and Benchmark process.

The idea was very simple. The host process (always a .NET console app) creates two anonymous pipes:

using AnonymousPipeServerStream inputFromBenchmark = new AnonymousPipeServerStream(PipeDirection.In, HandleInheritability.Inheritable);
using AnonymousPipeServerStream acknowledgments = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable);

Starts a new process and provides the handles as strings:

string args = benchmarkId.ToArguments(inputFromBenchmark.GetClientHandleAsString(), acknowledgments.GetClientHandleAsString());

Then the benchmark process parses the ids, creates a SafeFileHandle from it and provides it to FileStream that is later used for reading/writing:

private Stream OpenAnonymousPipe(string fileHandle, FileAccess access)
{
    var sfh = new SafeFileHandle(new IntPtr(int.Parse(fileHandle)), ownsHandle: true);
    return new FileStream(sfh, access);
}

It works fine for .NET, .NET Framework on all OSes but not with WASM.

On Linux, I am getting following error when trying to perform first read/write:

Error: Access to the path is denied.
    at $o (/home/adam/projects/performance/artifacts/bin/MicroBenchmarks/Release/net7.0/6030f12e-9262-45b4-8132-240f1ecaa9ea/bin/net7.0/browser-wasm/AppBundle/dotnet.js:5:37754)
    at Ws (/home/adam/projects/performance/artifacts/bin/MicroBenchmarks/Release/net7.0/6030f12e-9262-45b4-8132-240f1ecaa9ea/bin/net7.0/browser-wasm/AppBundle/dotnet.js:5:55546)
    at Object.b.javaScriptExports.call_entry_point (/home/adam/projects/performance/artifacts/bin/MicroBenchmarks/Release/net7.0/6030f12e-9262-45b4-8132-240f1ecaa9ea/bin/net7.0/browser-wasm/AppBundle/dotnet.js:5:58159)
    at Object.Te [as runMain] (/home/adam/projects/performance/artifacts/bin/MicroBenchmarks/Release/net7.0/6030f12e-9262-45b4-8132-240f1ecaa9ea/bin/net7.0/browser-wasm/AppBundle/dotnet.js:5:2713)
    at run (test-main.js:331:50)
Error: Access to the path is denied.
    at $o (/home/adam/projects/performance/artifacts/bin/MicroBenchmarks/Release/net7.0/6030f12e-9262-45b4-8132-240f1ecaa9ea/bin/net7.0/browser-wasm/AppBundle/dotnet.js:5:37754)
    at Ws (/home/adam/projects/performance/artifacts/bin/MicroBenchmarks/Release/net7.0/6030f12e-9262-45b4-8132-240f1ecaa9ea/bin/net7.0/browser-wasm/AppBundle/dotnet.js:5:55546)
    at Object.b.javaScriptExports.call_entry_point (/home/adam/projects/performance/artifacts/bin/MicroBenchmarks/Release/net7.0/6030f12e-9262-45b4-8132-240f1ecaa9ea/bin/net7.0/browser-wasm/AppBundle/dotnet.js:5:58159)
    at Object.Te [as runMain] (/home/adam/projects/performance/artifacts/bin/MicroBenchmarks/Release/net7.0/6030f12e-9262-45b4-8132-240f1ecaa9ea/bin/net7.0/browser-wasm/AppBundle/dotnet.js:5:2713)
    at run (test-main.js:331:50)
WASM EXIT 1

BenchmarkDotNet is using v8 to run the benchmarks (v8 --expose_wasm test-main.js).

@radical @lambdageek @naricc @vargaz Have you ever faced similar issue with WASM or have any idea what could be going wrong?

Can v8 be internally staring another process with no handle inheritance for some kind of sandboxing?
Can Emscripten not support anonymous pipes by design (security?)?

I would really like to get it working and avoid having dedicated code path for WASM.

Author: adamsitnik
Assignees: -
Labels:

arch-wasm

Milestone: -

@vargaz
Copy link
Contributor

vargaz commented Sep 10, 2022

v8/emscripten in general doesn't support communicating with the host machine except console output. So emitting structured output to the console and parsing it is a possible way to make (one way) communication work.

@ghost
Copy link

ghost commented Sep 12, 2022

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

Issue Details

In dotnet/BenchmarkDotNet#2092 I wanted to use Anonymous Pipes for communication between Host and Benchmark process.

The idea was very simple. The host process (always a .NET console app) creates two anonymous pipes:

using AnonymousPipeServerStream inputFromBenchmark = new AnonymousPipeServerStream(PipeDirection.In, HandleInheritability.Inheritable);
using AnonymousPipeServerStream acknowledgments = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable);

Starts a new process and provides the handles as strings:

string args = benchmarkId.ToArguments(inputFromBenchmark.GetClientHandleAsString(), acknowledgments.GetClientHandleAsString());

Then the benchmark process parses the ids, creates a SafeFileHandle from it and provides it to FileStream that is later used for reading/writing:

private Stream OpenAnonymousPipe(string fileHandle, FileAccess access)
{
    var sfh = new SafeFileHandle(new IntPtr(int.Parse(fileHandle)), ownsHandle: true);
    return new FileStream(sfh, access);
}

It works fine for .NET, .NET Framework on all OSes but not with WASM.

On Linux, I am getting following error when trying to perform first read/write:

Error: Access to the path is denied.
    at $o (/home/adam/projects/performance/artifacts/bin/MicroBenchmarks/Release/net7.0/6030f12e-9262-45b4-8132-240f1ecaa9ea/bin/net7.0/browser-wasm/AppBundle/dotnet.js:5:37754)
    at Ws (/home/adam/projects/performance/artifacts/bin/MicroBenchmarks/Release/net7.0/6030f12e-9262-45b4-8132-240f1ecaa9ea/bin/net7.0/browser-wasm/AppBundle/dotnet.js:5:55546)
    at Object.b.javaScriptExports.call_entry_point (/home/adam/projects/performance/artifacts/bin/MicroBenchmarks/Release/net7.0/6030f12e-9262-45b4-8132-240f1ecaa9ea/bin/net7.0/browser-wasm/AppBundle/dotnet.js:5:58159)
    at Object.Te [as runMain] (/home/adam/projects/performance/artifacts/bin/MicroBenchmarks/Release/net7.0/6030f12e-9262-45b4-8132-240f1ecaa9ea/bin/net7.0/browser-wasm/AppBundle/dotnet.js:5:2713)
    at run (test-main.js:331:50)
Error: Access to the path is denied.
    at $o (/home/adam/projects/performance/artifacts/bin/MicroBenchmarks/Release/net7.0/6030f12e-9262-45b4-8132-240f1ecaa9ea/bin/net7.0/browser-wasm/AppBundle/dotnet.js:5:37754)
    at Ws (/home/adam/projects/performance/artifacts/bin/MicroBenchmarks/Release/net7.0/6030f12e-9262-45b4-8132-240f1ecaa9ea/bin/net7.0/browser-wasm/AppBundle/dotnet.js:5:55546)
    at Object.b.javaScriptExports.call_entry_point (/home/adam/projects/performance/artifacts/bin/MicroBenchmarks/Release/net7.0/6030f12e-9262-45b4-8132-240f1ecaa9ea/bin/net7.0/browser-wasm/AppBundle/dotnet.js:5:58159)
    at Object.Te [as runMain] (/home/adam/projects/performance/artifacts/bin/MicroBenchmarks/Release/net7.0/6030f12e-9262-45b4-8132-240f1ecaa9ea/bin/net7.0/browser-wasm/AppBundle/dotnet.js:5:2713)
    at run (test-main.js:331:50)
WASM EXIT 1

BenchmarkDotNet is using v8 to run the benchmarks (v8 --expose_wasm test-main.js).

@radical @lambdageek @naricc @vargaz Have you ever faced similar issue with WASM or have any idea what could be going wrong?

Can v8 be internally staring another process with no handle inheritance for some kind of sandboxing?
Can Emscripten not support anonymous pipes by design (security?)?

I would really like to get it working and avoid having dedicated code path for WASM.

Author: adamsitnik
Assignees: -
Labels:

arch-wasm, area-System.IO, untriaged

Milestone: -

@adamsitnik
Copy link
Member Author

v8/emscripten in general doesn't support communicating with the host machine except console output.

@vargaz thanks!

@adamsitnik adamsitnik closed this as not planned Won't fix, can't repro, duplicate, stale Sep 12, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Sep 12, 2022
@lambdageek
Copy link
Member

@radical has done this in the context of the wasm app host he may have some suggestions about a robust approach

@ghost ghost locked as resolved and limited conversation to collaborators Oct 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture area-System.IO
Projects
None yet
Development

No branches or pull requests

4 participants