Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/service/node_static_inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ func (s *Service) nodePublishVolumeStaticInlineVolume(ctx context.Context, volum
duration := time.Since(startedAt)
logger.WithContext(ctx).Infof("pulled model: %s %s", reference, duration)

mountCtx, mountCancel := context.WithTimeout(context.WithoutCancel(ctx), 30*time.Second)
defer mountCancel()
if err := mounter.Mount(
ctx,
mountCtx,
mounter.NewBuilder().
Bind().
From(modelDir).
Expand Down
4 changes: 3 additions & 1 deletion pkg/service/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,10 @@ func (worker *Worker) pullModel(ctx context.Context, statusPath, volumeName, mou
}
defer worker.kmutex.Unlock(contextKey)

// Decouple from the kubelet RPC deadline so that large pulls aren't killed
// when kubelet times out and retries
var cancel context.CancelFunc
ctx, cancel = context.WithCancel(ctx)
ctx, cancel = context.WithCancel(context.WithoutCancel(ctx))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The cancel function returned by context.WithCancel should be called to release resources as soon as the operation is complete. Since this context is decoupled from the parent and has no deadline, failing to call cancel will result in a context leak until the garbage collector cleans it up. Adding a defer cancel() ensures that resources are released regardless of how the function exits.

Suggested change
ctx, cancel = context.WithCancel(context.WithoutCancel(ctx))
ctx, cancel = context.WithCancel(context.WithoutCancel(ctx))
defer cancel()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Should we only use WithoutCancel for the s.worker.PullModel of nodePublishVolumeStaticInlineVolume?

worker.contextMap.Set(contextKey, &cancel)
defer worker.contextMap.Set(contextKey, nil)

Expand Down
Loading