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

async stdin/stdout errors (compiling nimlsp on Windows) #121

Closed
veksha opened this issue Apr 19, 2022 · 16 comments · Fixed by #125
Closed

async stdin/stdout errors (compiling nimlsp on Windows) #121

veksha opened this issue Apr 19, 2022 · 16 comments · Fixed by #125

Comments

@veksha
Copy link

veksha commented Apr 19, 2022

Hello. I get exception at runtime (on Windows 11 x64). following lines seem to be the culprit:

import asyncfile, asyncdispatch
var
  ins = newAsyncFile(stdin.getOsFileHandle().AsyncFD)
  outs = newAsyncFile(stdout.getOsFileHandle().AsyncFD)
exception

D:\Programm\Nim\nim-inject\test.nim(8) test
D:\Programm\Nim\Nim-devel\lib\pure\asyncfile.nim(90) newAsyncFile
D:\Programm\Nim\Nim-devel\lib\pure\asyncdispatch.nim(341) register
D:\Programm\Nim\Nim-devel\lib\pure\includes\oserr.nim(94) raiseOSError
Error: unhandled exception: The parameter is incorrect
[OSError]

PMunch's comment on nim forum:

I think the error here is that the standard input on Windows isn't capable of async reads, and somehow the devel version of Nim detects this (although in the async runtime code, not as a limited type on the getOsFileHandle procedure). When you post this on GitHub please make sure to tag @haxscramper as well, they're the one who implemented the async logic.

@haxscramper

@PMunch
Copy link
Owner

PMunch commented Apr 19, 2022

Oh sorry, it wasn't @haxscramper, it was @bung87 who did the async stuff for NimLSP..

@bung87
Copy link
Contributor

bung87 commented Apr 19, 2022

get it , for now fallback to v0.3.2

@PMunch
Copy link
Owner

PMunch commented May 9, 2022

@bung87, did you have a chance to look into this further? It's not great that Windows users can't run the latest version.

@bung87
Copy link
Contributor

bung87 commented May 9, 2022

have not found any handy lib to archive this? do you have any recommend lib?

@PMunch
Copy link
Owner

PMunch commented May 9, 2022

Unfortunately it appears that standard input on Windows is not possible to read asynchronously. The only way to do this that I'm aware of is to spawn a second thread to read input.

@bung87
Copy link
Contributor

bung87 commented May 20, 2022

copy author original post from nim forum here.

D:\Programm\Nim\nim-inject\test.nim(8) test
D:\Programm\Nim\Nim-devel\lib\pure\asyncfile.nim(90) newAsyncFile
D:\Programm\Nim\Nim-devel\lib\pure\asyncdispatch.nim(341) register
D:\Programm\Nim\Nim-devel\lib\pure\includes\oserr.nim(94) raiseOSError
Error: unhandled exception: The parameter is incorrect

I have the latest Nim devel version. 1.7.1 dc4cc2dca53e3772efb3654a4ddbbe8350d1db43

PS: it actually compiles, but when you run - you got error.

@veksha
Copy link
Author

veksha commented May 20, 2022

@bung87 any ideas how to fix this?
found this asynctools/asyncproc.nim
can this info help you?

@PMunch
Copy link
Owner

PMunch commented May 20, 2022

I think the best way to handle this for now is to make it use async on Linux and the old synchronous behaviour on Windows. @bung87 would you be able to implement this?

@bung87
Copy link
Contributor

bung87 commented May 20, 2022

am able to do this , I'll first make sure the error whether or not cause by async logic, the error message is coming from windows os error, as @PMunch said there is only one commen on nim repo contains "The parameter is incorrect' in compiler file.

@bung87
Copy link
Contributor

bung87 commented May 20, 2022

@bung87 any ideas how to fix this?
found this asynctools/asyncproc.nim
can this info help you?

I've search a lot repos , found no perfect lib match the requires.

@bung87
Copy link
Contributor

bung87 commented May 20, 2022

yeah, windows is not support when fd.Handle is std io

    if createIoCompletionPort(fd.Handle, p.ioPort,
                              cast[CompletionKey](fd), 1) == 0:
      raiseOSError(osLastError())
    p.handles.incl(fd)

@bung87
Copy link
Contributor

bung87 commented May 20, 2022

https://github.com/bung87/nimlsp/actions/runs/2359268373 I try to use mutisync but encounter various kind of error @PMunch @veksha have time to check ?

@veksha
Copy link
Author

veksha commented May 20, 2022

@bung87 have you tried -d:asyncBackend=none as stated here:
https://nim-lang.org/docs/asyncdispatch.html#multiple-async-backend-support
if it will work somehow - it will be very small fix for our problem here. code must not be so overcomplicated. in my humble opinion. :)

@bung87
Copy link
Contributor

bung87 commented May 20, 2022

@bung87 have you tried -d:asyncBackend=none as stated here:
https://nim-lang.org/docs/asyncdispatch.html#multiple-async-backend-support
if it will work somehow - it will be very small fix for our problem here. code must not be so overcomplicated. in my humble opinion. :)

it does not work on my MBP I still get Exception message: index out of bounds, the container is empty when I run nimble test , weird ci report another kind error.

@bung87
Copy link
Contributor

bung87 commented May 20, 2022

@bung87
Copy link
Contributor

bung87 commented May 21, 2022

in the end I change to stream api.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants