* Add defer cancelFunc() to ensure context is always cancelled * Add ctx.Done() case in goroutine select to prevent goroutine leak * Fixes memory accumulation issue where goroutines were not properly cleaned up
This commit is contained in:
@@ -49,10 +49,14 @@ 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()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
select {
|
select {
|
||||||
case <-cancel:
|
case <-cancel:
|
||||||
cancelFunc()
|
cancelFunc()
|
||||||
|
case <-ctx.Done():
|
||||||
|
// Context already cancelled, exit goroutine
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user