wails icon indicating copy to clipboard operation
wails copied to clipboard

wails dev doesn't call OnShutdown

Open asdine opened this issue 1 year ago • 3 comments

Description

It seems that wails dev doesn't call the OnShudown function when restarting the app after detecting some code change. Tis prevents us from killing any background process / connections that have been spawned during the startup. If this behavior is by design, what is the best way to gracefully cleanup the resources while in dev mode?

To Reproduce

  • write a basic program with wails
  • exec any long running program in the background in the OnStartup function
  • close that process in the OnShutdown function
  • run wails dev
  • modify something in the code and save
  • run ps -ef | grep "<name of the exec'ed background process>"
  • should see the number of lines increase every time you modify the code

Expected behaviour

I was expecting the OnShutdown functions to be called

Screenshots

No response

Attempted Fixes

I tried to catch os.Interrupt and syscall.SIGTERM but it didn't work either.

System Details

Wails CLI v2.3.1

Scanning system - Please wait (this may take a long time)...Done.

# System

OS           | Ubuntu
Version      | 22.04
ID           | ubuntu
Go Version   | go1.20
Platform     | linux
Architecture | amd64

# Wails

Version         | v2.3.1
Package Manager | apt

# Dependencies

Dependency | Package Name          | Status    | Version
*docker    | docker.io             | Installed | 20.10.22
gcc        | build-essential       | Installed | 12.9ubuntu3
libgtk-3   | libgtk-3-dev          | Installed | 3.24.33-1ubuntu2
libwebkit  | libwebkit2gtk-4.0-dev | Installed | 2.38.3-0ubuntu0.22.04.1
npm        | npm                   | Installed | 9.2.0
*nsis      | nsis                  | Installed | v3.08-2
pkg-config | pkg-config            | Installed | 0.29.2-1ubuntu3
* - Optional Dependency

# Diagnosis

Your system is ready for Wails development!

Additional context

I'm running Wails on WSL 2

EDIT 1: Same behavior on macos

asdine avatar Feb 25 '23 09:02 asdine

Thanks for using Wails and opening this issue! I think it should call shutdown but can see we actually send a SIGKILL which would prevent this. However, I spent some time trying to send a SIGINT instead and weirdly, it shuts down the parent process. To reproduce, change this line: https://github.com/wailsapp/wails/blob/master/v2/internal/process/process.go#L53 to: err := p.cmd.Process.Signal(os.Interrupt)

The parent signal handler must be picking up the signal, which is annoying. I'll see if I have more time tomorrow to look at it.

leaanthony avatar Feb 27 '23 10:02 leaanthony

Same problem here (macOS),

func (a *App) shutdown(ctx context.Context) {
  panic("feel bad")
}

is never called

cgimenez avatar Apr 08 '23 13:04 cgimenez

I'm also having this issue on Windows 10 with Wails 2.6.0.

KodyJKing avatar Nov 06 '23 03:11 KodyJKing