Skip to content

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.

fix leaking goroutines (#7291)

Chris Lu0b51133fd30e
diff --git a/weed/mount/weedfs_file_lseek.go b/weed/mount/weedfs_file_lseek.go
index 73564fdbe6..a7e3a2b46c 100644
--- a/weed/mount/weedfs_file_lseek.go
+++ b/weed/mount/weedfs_file_lseek.go
@@ -58,10 +58,14 @@ func (wfs *WFS) Lseek(cancel <-chan struct{}, in *fuse.LseekIn, out *fuse.LseekO
// Create a context that will be cancelled when the cancel channel receives a signal
ctx, cancelFunc := context.WithCancel(context.Background())
+ defer cancelFunc() // Ensure cleanup
+
go func() {
select {
case <-cancel:
cancelFunc()
+ case <-ctx.Done():
+ // Clean exit when lseek operation completes
}
}()
diff --git a/weed/mount/weedfs_file_read.go b/weed/mount/weedfs_file_read.go
index 5a5a5efabf..c85478cd08 100644
--- a/weed/mount/weedfs_file_read.go
+++ b/weed/mount/weedfs_file_read.go
@@ -49,14 +49,13 @@ func (wfs *WFS) Read(cancel <-chan struct{}, in *fuse.ReadIn, buff []byte) (fuse
// Create a context that will be cancelled when the cancel channel receives a signal
ctx, cancelFunc := context.WithCancel(context.Background())
- defer cancelFunc()
-
+ defer cancelFunc() // Ensure cleanup
+
go func() {
select {
case <-cancel:
cancelFunc()
case <-ctx.Done():
- // Context already cancelled, exit goroutine
}
}()