SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
[bugfix] Fix interrupt hook overwritten bug
Alex Wang4db68669b6a2
diff --git a/weed/util/pprof.go b/weed/util/pprof.goindex 94bcdb8b37..3630175558 100644--- a/weed/util/pprof.go+++ b/weed/util/pprof.go@@ -14,7 +14,6 @@ func SetupProfiling(cpuProfile, memProfile string) {glog.Fatal(err)}pprof.StartCPUProfile(f)- defer pprof.StopCPUProfile()OnInterrupt(func() {pprof.StopCPUProfile()})diff --git a/weed/util/signal_handling.go b/weed/util/signal_handling.goindex 7da898738f..99447e8be6 100644--- a/weed/util/signal_handling.go+++ b/weed/util/signal_handling.go@@ -5,13 +5,16 @@ package utilimport ("os""os/signal"+ "sync""syscall")-func OnInterrupt(fn func()) {- // deal with control+c,etc- signalChan := make(chan os.Signal, 1)- // controlling terminal close, daemon not exit+var signalChan chan os.Signal+var hooks = make([]func(), 0)+var hookLock sync.Mutex++func init() {+ signalChan = make(chan os.Signal, 1)signal.Ignore(syscall.SIGHUP)signal.Notify(signalChan,os.Interrupt,@@ -24,8 +27,20 @@ func OnInterrupt(fn func()) {)go func() {for _ = range signalChan {- fn()+ for _, hook := range hooks {+ hook()+ }os.Exit(0)}}()}++func OnInterrupt(fn func()) {+ // prevent reentry+ hookLock.Lock()+ defer hookLock.Unlock()++ // deal with control+c,etc+ // controlling terminal close, daemon not exit+ hooks = append(hooks, fn)+}