Browse Source

fix leaking goroutines (#7291)

* fix leaking goroutines

* simplify

* simplify
master
Chris Lu 4 days ago
committed by GitHub
parent
commit
0b51133fd3
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 4
      weed/mount/weedfs_file_lseek.go
  2. 5
      weed/mount/weedfs_file_read.go

4
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 // Create a context that will be cancelled when the cancel channel receives a signal
ctx, cancelFunc := context.WithCancel(context.Background()) ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc() // Ensure cleanup
go func() { go func() {
select { select {
case <-cancel: case <-cancel:
cancelFunc() cancelFunc()
case <-ctx.Done():
// Clean exit when lseek operation completes
} }
}() }()

5
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 // Create a context that will be cancelled when the cancel channel receives a signal
ctx, cancelFunc := context.WithCancel(context.Background()) ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()
defer cancelFunc() // Ensure cleanup
go func() { go func() {
select { select {
case <-cancel: case <-cancel:
cancelFunc() cancelFunc()
case <-ctx.Done(): case <-ctx.Done():
// Context already cancelled, exit goroutine
} }
}() }()

Loading…
Cancel
Save