mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-12 06:48:45 +01:00
mount: remove the local control socket when the mount exits (#12560)
* mount: remove the local control socket when the mount exits weed mount listened on /tmp/seaweedfs-mount-<hash>.sock and removed it only when a later mount of the same directory started, so every unmount or SIGTERM left one socket file behind. Remove it on the normal return path and in the interrupt hook, unless a later mount of the same directory has already replaced it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: remove the control socket before a failed mount exits glog.Fatalf and glog.Exitf call os.Exit, which skips the deferred removal, so a mount that failed after creating its socket (mount point not available, fusermount failure) still left it behind. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * mount: register the socket cleanup hook before mount setup A SIGTERM that arrived while the mount was still setting up, for example waiting on the filer to create the mount root, exited through grace without running the deferred cleanup. Registering the hook right after the listener is created makes it run last, after the unmount and filesystem hooks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7f18576798
commit
b11af30cb1
4 files changed
+73
No files matched your search
@@ -5,6 +5,9 @@ package command
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
||||
@@ -213,3 +216,42 @@ func Test_ensureBucketAllowEmptyFolders(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_mountSocketCleanup(t *testing.T) {
|
||||
dir, err := os.MkdirTemp("", "swmnt")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { os.RemoveAll(dir) })
|
||||
socketPath := filepath.Join(dir, "mount.sock")
|
||||
listen := func() {
|
||||
l, err := net.Listen("unix", socketPath)
|
||||
if err != nil {
|
||||
t.Skipf("unix sockets unavailable: %v", err)
|
||||
}
|
||||
t.Cleanup(func() { l.Close() })
|
||||
}
|
||||
exists := func() bool {
|
||||
_, err := os.Lstat(socketPath)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
listen()
|
||||
removeMountSocket := mountSocketCleanup(socketPath)
|
||||
removeMountSocket()
|
||||
removeMountSocket()
|
||||
if exists() {
|
||||
t.Fatalf("%s is still there after the mount exited", socketPath)
|
||||
}
|
||||
|
||||
listen()
|
||||
removeMountSocket = mountSocketCleanup(socketPath)
|
||||
if err := os.Remove(socketPath); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
listen()
|
||||
removeMountSocket()
|
||||
if !exists() {
|
||||
t.Fatalf("exiting mount removed the socket of a later mount of the same directory")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user