-
Notifications
You must be signed in to change notification settings - Fork 30
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
Nimlangsever + nimsuggest processes non being killed when using choosenim #184
Comments
Same thing happens on Windows 11 |
What are the command line options of nimsuggest, i.e. what does |
By doing so, I realized that using After opening VSCode: no nimlangserver/nimsuggest processes
After opening
after closing vscode (one of the two nimsuggest goes defunct)
after reopoening vscode on
n2 (new one)
I see two points here:
|
Can you make the following changes in nimlangserver.nim.cfg:
Then recompile nimlangserver using
|
↓ VSCode open
↑ VSCode closed
↓ killall nimlangserger
EOF |
Hmm, here's what the end of the log is supposed to look after closing VS Code:
After that, I get no leftover processes - neither nimlangserver, nor nimsuggest. So, this means something in your setup is different, and we need to figure this out, so I can reproduce the bug. Can you provide more information about your VS Code plugins and versions, your desktop environment (I'm using GNOME), window manager, etc. |
Interesting. Seems actually related to my environment. OS
VSCode
Gnome 42.9 I'll try to repeat the experiment in a pristine VSCode environment (with just nim extension) and give feedback |
I've created a new VSCode profile (File > Preferences > Profiles) with nothing except nim-lang extension. Here's the full
but even using this I experience same behaviour: This should help ruling out quite large group of possible causes |
I went print debugging langserver code this proc stop*(self: Nimsuggest) =
debug "Stopping nimsuggest for ", root = self.root
try:
debug "A"
self.process.kill()
debug "B"
self.process.close()
debug "C"
except Exception:
debug "Err"
debug getCurrentExceptionMsg()
discard prints this in log DBG Stopping nimsuggest for root=/home/arkanoid/nim/vscode_playground/src/front/front.nim
DBG A
DBG B
UPDATE: print debugging import posix
import streams
proc stop*(self: Nimsuggest) =
proc close(p: Process) =
debug "CA ", pid=p.processID
if poParentStreams notin p.options:
if p.inStream != nil:
debug "CB", pid=p.processID
close(p.inStream)
else:
debug "CC", pid=p.processID
discard close(p.inHandle)
if p.outStream != nil:
debug "CD", pid=p.processID
close(p.outStream)
else:
debug "CE", pid=p.processID
discard close(p.outHandle)
if p.errStream != nil:
debug "CF", pid=p.processID
close(p.errStream)
else:
debug "CG", pid=p.processID
discard close(p.errHandle)
debug "CH", pid=p.processID
debug "Stopping nimsuggest for ", root = self.root
try:
debug "A", pid=self.process.processID
self.process.kill()
debug "B", pid=self.process.processID
self.process.close()
debug "C", pid=self.process.processID
except Exception:
debug "Err", pid=self.process.processID
debug getCurrentExceptionMsg()
discard log
so it seems to hang inside
seems that
UPDATE2: import logging
var fileLog = newFileLogger("handler.log")
addHandler(fileLog)
proc fsClose(s: Stream) =
{.cast(raises:[]).}:
{.cast(tags: []).}:
info "fsClose A " & $FileStream(s).f.repr
if FileStream(s).f != nil:
info "fsClose B " & $FileStream(s).f.repr
close(FileStream(s).f)
info "fsClose C " & $FileStream(s).f.repr
FileStream(s).f = nil
info "fsClose D " & $FileStream(s).f.repr when vscode is closed, the following linea are appended to
strace -p<nimlangserver_pid> -s 1000000 --decode-fds
UPDATE3: proc stop*(self: Nimsuggest) =
debug "Stopping nimsuggest for ", root = self.root
try:
self.process.kill()
# self.process.close()
dicard self.process.waitForExit()
except Exception:
debug getCurrentExceptionMsg()
discard UPDATE4: Line 360 in 3eb83da
leaving Line 238 in 3eb83da
UPDATE5: I can confirm that the line that prevents nimlangserver to close stderr of Zombified nimsuggest process is: Line 240 in 3eb83da
I've tried some educated guess solution, but this problem goes beyond my knowledge of pipes, futexes, and cross-platform IPC I/O in general. Also I see some hacks I don't quite understand. |
Hmm, it's possible that the logStderr is causing this. It does a blocking read on the fd in another thread. While this blocking call is in progress, we call close() on the fd in the main thread.
So, it looks like it could cause some nasty race condition. However, the documented behavior under Linux should not cause close() to block. And I'm not experiencing this under Fedora 39 (with kernel-6.7.4-200.fc39.x86_64 and glibc-2.38-16.fc39.x86_64). Could it be something Ubuntu-specific? I need to try this in a VM. Another question: Does it happen on every project, or just this one? Is there something special about https://github.com/arkanoid87/nim_vscode_playground or does it also happen in just an empty dir with hello.nim like this:
? |
Please file a separate bug report for Windows, with the exact steps to reproduce. Include, at least, Nim and nimsuggest version, how did you install them, VS Code version, vscode-nim plugin version, other plugins that you have installed, your VS Code config file, the project you're testing this on, etc. |
it happens even with minimal project: $ mkdir minimal
$ cd minimal
$ echo 'echo "hello world!"' > main.nim
$ code .
# (quit vscode)
$ ps -aux | grep nimsuggest
arkanoid 319123 0.0 0.0 0 0 ? Z 22:23 0:00 [nimsuggest] <defunct>
arkanoid 319126 0.2 0.1 41272 32384 ? Sl 22:23 0:00 /home/arkanoid/.choosenim/toolchains/nim-2.0.2/bin/nimsuggest /home/arkanoid/nim/minimal/main.nim --v4 --autobind --clientProcessId:319105
arkanoid 319753 0.0 0.0 9220 2432 pts/1 S+ 22:25 0:00 grep --color=auto nimsuggest
$ ps -aux | grep nimlangserver
arkanoid 319105 0.0 0.0 218328 11948 ? Sl 22:23 0:00 /home/arkanoid/.nimble/pkgs2/nimlangserver-1.2.0-95de85fae4485dcd850ada31e200d15671a00c4a/nimlangserver --stdio
arkanoid 319846 0.0 0.0 9220 2432 pts/1 S+ 22:28 0:00 grep --color=auto nimlangserver |
Very strange. Tried this in a VM under Ubuntu 22.04.3 LTS (with latest updates) and I still couldn't reproduce it. What is your kernel version? The close and read calls are actually syscalls of the kernel, so it could be kernel version-related. |
$ uname -a
Linux 6.5.0-17-generic #17~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 16 14:32:32 UTC 2 x86_64 x86_64 x86_64 GNU/Linux from
I'm gonna test on a different machine, as this is getting spooky |
if this is relevant: i have the same problem under arch. dangling processes after closing vscode.
After closing vscode
|
Please provide nimsuggest.log (see above how to enable logging), your VS Code version, your Nim version, your nimsuggest version, and how did you install them. |
Here we go: The OS (freshly updated)
The Kernel:
The Code
The langserver
The nimsuggest
The nimsuggestlog with Debugging enabled:
ps auxw
pstree
strace -p 405902 (nimsuggest on main.nim)
Status on nimsuggest
This is the nimsuggest zombie
This is the status of the nimlangserver
|
The nim project i use is a simple hello world projekt with 3 files: src/example.nim src/test.nim and main.nim. The settings.json of vscode is:
|
I think I found out what's causing this mysterious issue. It appears that the problem is being caused by choosenim. I'm not using choosenim and I don't have this problem. Can you try without choosenim to confirm? |
you mean to use nimsuggest in PATH without choosenim shims? |
Yes, that's one way to test it without uninstalling choosenim completely. |
I think you nailed it! problem present: problem absent: |
it is possible to reproduce this issue excluding nimlangserver and vscode extension completely from terminal with choosenim shims (nim 2.0.2) $ md5sum "$(which nimsuggest)"
9d2c46b8ea6cc1288e959053b734d749 /home/arkanoid/.nimble/bin//nimsuggest
$ echo 'echo "Hello, World!"' > main.nim
$ nimsuggest main.nim from other terminal $ ps -fC nimsuggest
UID PID PPID C STIME TTY TIME CMD
arkanoid 1156404 488153 0 18:39 pts/8 00:00:00 nimsuggest main.nim
arkanoid 1156405 1156404 0 18:39 pts/8 00:00:00 /home/arkanoid/.choosenim/toolchains/nim-2.0.2/bin/nimsuggest main.nim
$ kill -TERM 1156404
$ ps -fC nimsuggest
UID PID PPID C STIME TTY TIME CMD
arkanoid 1156405 2412 0 18:39 pts/8 00:00:00 /home/arkanoid/.choosenim/toolchains/nim-2.0.2/bin/nimsuggest main.nim sending SIGKILL or SIGINT instead of SIGTERM makes no difference using nimsuggest directly without choosenim shims works as intended EDIT: there are quite some interesting differences between running and killing choosenim proxy manually and closing vscode manual running choosenim proxy vscode $ ps -fC nimsuggest
UID PID PPID C STIME TTY TIME CMD
arkanoid 1162029 1162023 0 20:14 ? 00:00:00 nimsuggest /home/arkanoid/nim/nimsuggest_problem/main.nim --v4 --autobind --clientProcessId:1162023
arkanoid 1162032 1162029 0 20:14 ? 00:00:00 /home/arkanoid/.choosenim/toolchains/nim-2.0.2/bin/nimsuggest /home/arkanoid/nim/nimsuggest_problem/main.nim --v4 --autobind --clientProcessId:1162023
$ pstree -a -p 1162023
nimlangserver,1162023 --stdio
├─nimsuggest,1162029 /home/arkanoid/nim/nimsuggest_problem/main.nim --v4 --autobind --clientProcessId:1162023
│ └─nimsuggest,1162032 /home/arkanoid/nim/nimsuggest_problem/main.nim --v4 --autobind --clientProcessId:1162023
│ ├─{nimsuggest},1162051
│ └─{nimsuggest},1162052
├─{nimlangserver},1162024
└─{nimlangserver},1162031 after close $ ps -fC nimsuggest
UID PID PPID C STIME TTY TIME CMD
arkanoid 1162029 1162023 0 20:14 ? 00:00:00 [nimsuggest] <defunct>
arkanoid 1162032 2412 0 20:14 ? 00:00:00 /home/arkanoid/.choosenim/toolchains/nim-2.0.2/bin/nimsuggest /home/arkanoid/nim/nimsuggest_problem/main.nim --v4 --autobind --clientProcessId:1162023
$ pstree -a -p 1162023
nimlangserver,1162023 --stdio
├─(nimsuggest,1162029)
└─{nimlangserver},1162031 |
TLDR; each vscode instance runs a nimlangserver process, each nim tab file runs two nimsuggest processes, when vscode is closed nimlangserver is not killed and one nimsuggest goes defunct. Repeatable steps until OOM
OS
VSCode via official repo .deb
nimlangserver installed/upgraded via nimble
nimsuggest installed/upgraded via nimble
minimal project (karax frontend, prologue backend, atlas scaffold): https://github.com/arkanoid87/nim_vscode_playground
Test scenario setup:
Monitor processes (optional) run in different windows:
killall nimlangserver && killall nimsuggest && killall code && code .
: nimlangserver =+ 1src/front/front.nim
: nimsuggest += 2src/back/back.nim
: nimsuggest += 2code .
nimlangserver =+ 1src/front/front.nim
: nimsuggest += 2src/back/back.nim
: nimsuggest += 2The text was updated successfully, but these errors were encountered: