Skip to content

Commit

Permalink
Only listen for the USR1 signals on some platforms. Fixes #157.
Browse files Browse the repository at this point in the history
  • Loading branch information
xyproto committed Jan 20, 2025
1 parent 3d010e4 commit 61e229a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
16 changes: 2 additions & 14 deletions engine/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ import (
"log"
"net/http"
"os"
"os/signal"
"path/filepath"
"runtime"
"strconv"
"strings"
"sync"
"syscall"
"time"

"github.com/evanw/esbuild/pkg/api"
Expand Down Expand Up @@ -705,18 +703,8 @@ func (ac *Config) MustServe(mux *http.ServeMux) error {
platformdep.IgnoreTerminalResizeSignal()
}

// Listen for SIGUSR1 to clear the cache
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGUSR1)
go func() {
for {
// Wait for a signal of the type given to signal.Notify
sig := <-signals
logrus.Infof("Received %v", sig)
// Launch a goroutine for clearing the cache
go ac.ClearCache()
}
}()
// Setup a signal handler for clearing the cache when USR1 is received, for some platforms
platformdep.SetupSignals(ac.ClearCache, logrus.Infof)

// Run the shutdown functions if graceful does not
defer ac.GenerateShutdownFunction(nil)()
Expand Down
7 changes: 7 additions & 0 deletions platformdep/signals.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build windows

package platformdep

func SetupSignals(clearCacheFunction func(), printFunction func(format string, args ...interface{})) {
return
}
24 changes: 24 additions & 0 deletions platformdep/signals_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//go:build !windows

package platformdep

import (
"os"
"os/signal"
"syscall"
)

func SetupSignals(clearCacheFunction func(), printFunction func(format string, args ...interface{})) {
// Listen for SIGUSR1 to clear the cache
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGUSR1)
go func() {
for {
// Wait for a signal of the type given to signal.Notify
sig := <-signals
printFunction("Received %v", sig)
// Launch a goroutine for clearing the cache
go clearCacheFunction()
}
}()
}

0 comments on commit 61e229a

Please sign in to comment.