mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-10-07 15:34:23 +08:00
fix leaking goroutines (#7291)
* fix leaking goroutines * simplify * simplify
This commit is contained in:
@@ -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
|
||||
}
|
||||
}()
|
||||
|
||||
|
@@ -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
|
||||
}
|
||||
}()
|
||||
|
||||
|
Reference in New Issue
Block a user