8000 fix: handle parent process exit to ensure MCP Server shutdown by cfc4n · Pull Request #33 · gojue/moling · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: handle parent process exit to ensure MCP Server shutdown #33

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

Merged
merged 1 commit into from
Apr 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,23 @@ func mlsCommandFunc(command *cobra.Command, args []string) error {
sigChan := make(chan os.Signal, 2)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)

// 创建一个 goroutine 来判断父进程是否退出
// Claude Desktop 0.9.2 退出时,没有向MCP Server发送 SIGTERM信号,导致MCP 不能正常退出。
// fix https://github.com/gojue/moling/issues/32
go func() {
ppid := os.Getppid()
for {
time.Sleep(1 * time.Second)
newPpid := os.Getppid()
if newPpid == 1 {
loger.Info().Msgf("parent process changed,origin PPid:%d, New PPid:%d", ppid, newPpid)
loger.Warn().Msg("parent process exited")
sigChan <- syscall.SIGTERM
break
}
}
}()

// 等待信号
_ = <-sigChan
loger.Info().Msg("Received signal, shutting down...")
Expand Down
Loading
0