From 6ddc2b1d6128bf305cd6a78ae8e90587c37b8365 Mon Sep 17 00:00:00 2001 From: Andrii Fylypiuk Date: Mon, 9 Jun 2025 23:17:57 +0200 Subject: [PATCH] Fixes vfs workers to close root on error Ensures the vfs root is closed when an error occurs during file operations in vfs workers, preventing potential resource leaks. --- internal/pss/vfs_workers.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/pss/vfs_workers.go b/internal/pss/vfs_workers.go index ee8ab67..e8a9bbc 100644 --- a/internal/pss/vfs_workers.go +++ b/internal/pss/vfs_workers.go @@ -44,8 +44,11 @@ func (v *vfsReadFile) execute(ctx context.Context, p *pss, timeout time.Duration commandCtx, cancel := context.WithTimeout(ctx, timeout) defer cancel() - file, err := p.vfs.Root(vent.VMRead).OpenAt(commandCtx, v.filePath) + root := p.vfs.Root(vent.VMRead) + + file, err := root.OpenAt(commandCtx, v.filePath) if err != nil { + _ = root.CloseCtx(commandCtx) return err } p.logger.Debug("file opened successfully", "path", v.filePath) @@ -195,8 +198,11 @@ func (v *vfsAddFile) execute(ctx context.Context, p *pss, timeout time.Duration) commandCtx, cancel := context.WithTimeout(ctx, timeout) defer cancel() - dir, err := p.vfs.Root(vent.VMWrite).OpenAt(commandCtx, v.path) + root := p.vfs.Root(vent.VMWrite) + + dir, err := root.OpenAt(commandCtx, v.path) if err != nil { + _ = root.CloseCtx(commandCtx) p.logger.Error("failed to open dir", "path", v.path, "err", err) return err }