microsoft / vs-pty.net

Fork pseudoterminals in C#
MIT License
49 stars 18 forks source link

System.IO.IOException: Invalid handle to path "[Unknown]" on Mono #33

Closed bnuzhouwei closed 10 months ago

bnuzhouwei commented 1 year ago

The error still exits in Mono:

import clr, System
from Pty.Net import *
class Pty:
    def __init__(self, name, cols=180, rows=500):
        self.name = name
        self.started = ph.dd.now()
        self.host = "127.0.0.1"
        self.cols = cols
        self.rows = rows
        app = "/bin/bash"
        options = PtyOptions()
        options.Name = name
        options.Cols = 180
        options.Rows = 500
        options.Cwd = "/root"
        options.App = app
        self.pty = PtyProvider.SpawnAsync(options, System.Threading.CancellationToken()).GetAwaiter().GetResult()
pty = Pty("lo")
System.IO.IOException: Invalid handle to path "[Unknown]"
  at System.IO.FileStream.Init (Microsoft.Win32.SafeHandles.SafeFileHandle safeHandle, System.IO.FileAccess access, System.Boolean ownsHandle, System.Int32 bufferSize, System.Boolean isAsync, System.Boolean isConsoleWrapper) [0x0006a] in <a5426229307d4283803b6b7e2cdc86e0>:0 
  at System.IO.FileStream..ctor (Microsoft.Win32.SafeHandles.SafeFileHandle handle, System.IO.FileAccess access, System.Int32 bufferSize, System.Boolean isAsync) [0x00011] in <a5426229307d4283803b6b7e2cdc86e0>:0 
  at Pty.Net.Unix.PtyStream..ctor (System.Int32 fd, System.IO.FileAccess fileAccess) [0x0000d] in <c5151a3d755045f2a06d1d18f46d910c>:0 
  at (wrapper remoting-invoke-with-check) Pty.Net.Unix.PtyStream..ctor(int,System.IO.FileAccess)
  at Pty.Net.Unix.PtyConnection..ctor (System.Int32 controller, System.Int32 pid) [0x00012] in <c5151a3d755045f2a06d1d18f46d910c>:0 
  at Pty.Net.Linux.PtyConnection..ctor (System.Int32 controller, System.Int32 pid) [0x00000] in <c5151a3d755045f2a06d1d18f46d910c>:0 
  at Pty.Net.Linux.PtyProvider.StartTerminalAsync (Pty.Net.PtyOptions options, System.Diagnostics.TraceSource trace, System.Threading.CancellationToken cancellationToken) [0x0011f] in <c5151a3d755045f2a06d1d18f46d910c>:0 
  at Pty.Net.PtyProvider.SpawnAsync (Pty.Net.PtyOptions options, System.Threading.CancellationToken cancellationToken) [0x0007b] in <c5151a3d755045f2a06d1d18f46d910c>:0 
  at (wrapper delegate-invoke) 
RHamers commented 10 months ago

Did you manage to figure this one out?

bnuzhouwei commented 10 months ago

Did you manage to figure this one out?

No, I have upgrade my appliction to net6, so i gived up .

RHamers commented 10 months ago

@javierdlg Do you have some input here maybe? I'm on Ubuntu 22.04 with Mono btw.

RHamers commented 10 months ago

Seems related to this bug in mono.

javierdlg commented 10 months ago

@RHamers seems like you've found the root bug for this issue. Could you try using .Net 6 or higher instead of Mono?

RHamers commented 10 months ago

Hey, yeah I'm trying a different approach yet I haven't gotten it to work properly. I'm bound to Mono however, I have a solution working on Windows which works.

I pulled the nuget package into a new dotnet8 project and build a thin API around vs-pty using TCP clients. Then I can simply build a self-contained app and run it on the target platform. This works perfectly fine for windows, yet on ubuntu 22.04 I get a segfault during start up, which I think is related to this.

My next step was to rollback to an earlier version of dotnet and try it that way.

RHamers commented 10 months ago

It seems when I build with dotnet6 I dont get the segfault error. I have no output though, but that's likely an issue on my side. I'll try and fix it.

RHamers commented 10 months ago

OK, I fixed it by starting "/bin/bash" instead of "sh" as app on Ubuntu 22.04. :D