Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Cai <jcai@gitlab.com>2022-09-23 00:23:06 +0300
committerJohn Cai <jcai@gitlab.com>2022-09-28 17:51:58 +0300
commit9e68a3f744c56dd5473aa031fb4fdacd3a839cea (patch)
tree6d8226dff317e1e4c3b2f2869ae15d9f9e16aed2
parentea2c78dcc1d6aa000ac47ef31e6c524d33c1f924 (diff)
git: Add gitalyPid option to NewExecCommandFactoryjc-spawn-git-in-pgid
We want all git commands to be tied to a pgid, the gitaly process. This way, when gitaly gets killed, all git processes can be killed alongside it, in case there are any zombie processes hanging around. Add a gitalyPid option to the NewExecCommandFactory() constructor, and update the callsites with the option. Changelog: changed
-rw-r--r--cmd/gitaly/main.go5
-rw-r--r--internal/git/command_factory.go13
2 files changed, 17 insertions, 1 deletions
diff --git a/cmd/gitaly/main.go b/cmd/gitaly/main.go
index e1097b866..24bc65a0a 100644
--- a/cmd/gitaly/main.go
+++ b/cmd/gitaly/main.go
@@ -196,7 +196,10 @@ func run(cfg config.Cfg) error {
}
skipHooks, _ := env.GetBool("GITALY_TESTING_NO_GIT_HOOKS", false)
- var commandFactoryOpts []git.ExecCommandFactoryOption
+ commandFactoryOpts := []git.ExecCommandFactoryOption{
+ git.WithGitalyPid(os.Getpid()),
+ }
+
if skipHooks {
commandFactoryOpts = append(commandFactoryOpts, git.WithSkipHooks())
}
diff --git a/internal/git/command_factory.go b/internal/git/command_factory.go
index dae719935..53444b43b 100644
--- a/internal/git/command_factory.go
+++ b/internal/git/command_factory.go
@@ -43,6 +43,7 @@ type CommandFactory interface {
type execCommandFactoryConfig struct {
hooksPath string
gitBinaryPath string
+ gitalyPid int
}
// ExecCommandFactoryOption is an option that can be passed to NewExecCommandFactory.
@@ -69,6 +70,14 @@ func WithGitBinaryPath(path string) ExecCommandFactoryOption {
}
}
+// WithGitalyPid will cause new commands to be started under the gitaly pid as
+// the pgid
+func WithGitalyPid(gitalyPid int) ExecCommandFactoryOption {
+ return func(cfg *execCommandFactoryConfig) {
+ cfg.gitalyPid = gitalyPid
+ }
+}
+
type hookDirectories struct {
tempHooksPath string
}
@@ -89,6 +98,8 @@ type ExecCommandFactory struct {
cachedGitVersionLock sync.RWMutex
cachedGitVersionByBinary map[string]cachedGitVersion
+
+ gitalyPid int
}
// NewExecCommandFactory returns a new instance of initialized ExecCommandFactory. The returned
@@ -138,6 +149,7 @@ func NewExecCommandFactory(cfg config.Cfg, opts ...ExecCommandFactoryOption) (_
),
hookDirs: hookDirectories,
cachedGitVersionByBinary: make(map[string]cachedGitVersion),
+ gitalyPid: factoryCfg.gitalyPid,
}
return gitCmdFactory, runCleanups, nil
@@ -413,6 +425,7 @@ func (cf *ExecCommandFactory) newCommand(ctx context.Context, repo repository.Gi
command.WithCommandName("git", sc.Subcommand()),
command.WithCgroup(cf.cgroupsManager, repo),
command.WithCommandGitVersion(cmdGitVersion.String()),
+ command.WithParent(cf.gitalyPid),
)...)
if err != nil {
return nil, err