fix leaking goroutines (#7291)

* fix leaking goroutines

* simplify

* simplify
This commit is contained in:
Chris Lu
2025-09-30 20:20:24 -07:00
committed by GitHub
parent fc89e97af7
commit 0b51133fd3
2 changed files with 6 additions and 3 deletions

View File

@@ -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
}
}()

View File

@@ -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
}
}()