diff options
author | Pavlo Strokov <pstrokov@gitlab.com> | 2020-11-08 20:36:00 +0300 |
---|---|---|
committer | Pavlo Strokov <pstrokov@gitlab.com> | 2020-11-12 15:57:47 +0300 |
commit | 70c002645cafa7101ae2ad5be52c08f8ebde71de (patch) | |
tree | c86a2b7b8a7cd2f4518121db33d107e0171d32a6 | |
parent | 3c616d7f3d69e7e14971bc8facfa4298675200ad (diff) |
Go implementation of UserSquash RPC may fail to cleanup
We should not use context.Context bound to the request as
it could be cancelled or expire before cleanup operation
executed. This issue could lead to a lot of different
issues like repository inconsistent configuration,
consumption of additional space, etc. To address this
issue we should use SuppressCancellation wrapper for the
context. The wrapped context will suppress cancellation
or expiration of the parent context and at the same time
will provide all values set into it in the interceptors,
etc. Because SafeCmd and related func allowed to call
only with context that could be cancelled we should use
context.WithCancel wrapping on the result of the
SuppressCancellation call.
Part of: https://gitlab.com/gitlab-org/gitaly/-/issues/3075
-rw-r--r-- | internal/gitaly/service/operations/squash.go | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/internal/gitaly/service/operations/squash.go b/internal/gitaly/service/operations/squash.go index 8d7309c47..86bbc211c 100644 --- a/internal/gitaly/service/operations/squash.go +++ b/internal/gitaly/service/operations/squash.go @@ -195,6 +195,9 @@ func (s *server) userSquashWithDiffInFiles(ctx context.Context, req *gitalypb.Us } defer func(worktreeName string) { + ctx, cancel := context.WithCancel(command.SuppressCancellation(ctx)) + defer cancel() + if err := s.removeWorktree(ctx, repo, worktreeName); err != nil { ctxlogrus.Extract(ctx).WithField("worktree_name", worktreeName).WithError(err).Error("failed to remove worktree") } @@ -286,6 +289,9 @@ func (s *server) userSquashWithNoDiff(ctx context.Context, req *gitalypb.UserSqu } defer func(worktreeName string) { + ctx, cancel := context.WithCancel(command.SuppressCancellation(ctx)) + defer cancel() + if err := s.removeWorktree(ctx, repo, worktreeName); err != nil { ctxlogrus.Extract(ctx).WithField("worktree_name", worktreeName).WithError(err).Error("failed to remove worktree") } |