-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Server shutdown in case the client process has exited unexpectedly. (#64
) Monitor the client process ID, received in the initialize request and shutdown the server in case the client process is found to be dead. This fixes the remaining nimlangserver processes after an IDE crash, or in case of broken IDE and/or plugin not sending the proper shutdown and exit commands to the server.
- Loading branch information
Showing
2 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Monitor a client process and shutdown the current process, if the client | ||
# process is found to be dead | ||
|
||
import os | ||
|
||
when defined(posix): | ||
import posix_utils | ||
import posix | ||
|
||
when defined(windows): | ||
import winlean | ||
|
||
when defined(posix): | ||
proc monitorClientProcessIdThreadProc(pid: int) {.thread.} = | ||
while true: | ||
sleep(1000) | ||
try: | ||
sendSignal(Pid(pid), 0) | ||
except: | ||
discard kill(Pid(getCurrentProcessId()), cint(SIGTERM)) | ||
|
||
when defined(windows): | ||
proc monitorClientProcessIdThreadProc(pid: int) {.thread.} = | ||
var process = openProcess(SYNCHRONIZE, 0, DWORD(pid)) | ||
if process != 0: | ||
discard waitForSingleObject(process, INFINITE) | ||
discard closeHandle(process) | ||
quit(0) | ||
|
||
var tid: Thread[int] | ||
|
||
proc hookProcMonitor*(pid: int) = | ||
when defined(posix) or defined(windows): | ||
createThread(tid, monitorClientProcessIdThreadProc, pid) |