mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
[v3] Fix: Vite server not cleaned up when build fails (#4436)
* fix: properly clean up Vite server when build fails Ensures the Vite server process is terminated when a build fails during 'wails3 dev', preventing port conflicts on subsequent runs. Fixes #4403 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: add defer for watcher cleanup and tidy up returns - Add defer cleanup() to ensure resources are always freed - Remove manual cleanup in error path since defer handles it - Simplify error handling for better maintainability Addresses feedback on PR #4436 * fix: prevent channel deadlock in watcher cleanup - Separate cleanup logic from channel notification - cleanup() only stops the engine - signalCleanup() handles both cleanup and channel notification - Prevents deadlock when function exits normally --------- Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
parent
55277fd695
commit
b0871c19e1
2 changed files with 17 additions and 2 deletions
|
|
@ -24,6 +24,7 @@ After processing, the content will be moved to the main changelog and this file
|
|||
|
||||
## Fixed
|
||||
<!-- Bug fixes -->
|
||||
- Fix Vite server not being cleaned up when build fails (#4403)
|
||||
|
||||
## Deprecated
|
||||
<!-- Soon-to-be removed features -->
|
||||
|
|
|
|||
|
|
@ -35,17 +35,31 @@ func Watcher(options *WatcherOptions) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
signalHandler := signal.NewSignalHandler(func() {
|
||||
|
||||
// Setup cleanup function that stops the engine
|
||||
cleanup := func() {
|
||||
watcherEngine.Stop()
|
||||
}
|
||||
defer cleanup()
|
||||
|
||||
// Signal handler needs to notify when to stop
|
||||
signalCleanup := func() {
|
||||
cleanup()
|
||||
stopChan <- struct{}{}
|
||||
})
|
||||
}
|
||||
|
||||
signalHandler := signal.NewSignalHandler(signalCleanup)
|
||||
signalHandler.ExitMessage = func(sig os.Signal) string {
|
||||
return ""
|
||||
}
|
||||
signalHandler.Start()
|
||||
|
||||
// Start the engine
|
||||
err = watcherEngine.Start()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
<-stopChan
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue