Skip to content

Commit b605305

Browse files
author
Dev Agent
committed
Add git tree operation timeout config
1 parent 89b5266 commit b605305

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

builder/git/gitserver/gitaly/client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type Client struct {
3333
smartHttpClient gitalypb.SmartHTTPServiceClient
3434
remoteClient gitalypb.RemoteServiceClient
3535
timeout time.Duration
36+
treeTimeout time.Duration
3637
repoStore database.RepoStore
3738
}
3839

@@ -91,6 +92,7 @@ func NewClient(config *config.Config) (*Client, error) {
9192
}
9293

9394
timeoutTime := time.Duration(config.Git.OperationTimeout) * time.Second
95+
treeTimeoutTime := time.Duration(config.Git.TreeOperationTimeout) * time.Second
9496
return &Client{
9597
config: config,
9698
sidechannelRegistry: sidechannelRegistry,
@@ -104,5 +106,6 @@ func NewClient(config *config.Config) (*Client, error) {
104106
remoteClient: remoteClient,
105107
timeout: timeoutTime,
106108
repoStore: database.NewRepoStore(),
109+
treeTimeout: treeTimeoutTime,
107110
}, nil
108111
}

builder/git/gitserver/gitaly/file.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ func (c *Client) getBlobInfo(ctx context.Context, repo *gitalypb.Repository, pat
610610

611611
func (c *Client) GetRepoFileTree(ctx context.Context, req gitserver.GetRepoInfoByPathReq) ([]*types.File, error) {
612612
var files []*types.File
613-
ctx, cancel := context.WithTimeout(ctx, time.Second*3)
613+
ctx, cancel := context.WithTimeout(ctx, c.treeTimeout)
614614
defer cancel()
615615

616616
req.Path = strings.TrimPrefix(req.Path, "/")
@@ -757,7 +757,7 @@ func (c *Client) GetRepoFileTree(ctx context.Context, req gitserver.GetRepoInfoB
757757
}
758758

759759
func (c *Client) GetTree(ctx context.Context, req types.GetTreeRequest) (*types.GetRepoFileTreeResp, error) {
760-
ctx, cancel := context.WithTimeout(ctx, time.Second*3)
760+
ctx, cancel := context.WithTimeout(ctx, c.treeTimeout)
761761
defer cancel()
762762

763763
req.Path = strings.TrimPrefix(req.Path, "/")
@@ -842,7 +842,7 @@ func (c *Client) GetTree(ctx context.Context, req types.GetTreeRequest) (*types.
842842

843843
func (c *Client) GetLogsTree(ctx context.Context, req types.GetLogsTreeRequest) (*types.LogsTreeResp, error) {
844844
var resp []*types.CommitForTree
845-
ctx, cancel := context.WithTimeout(ctx, time.Second*3)
845+
ctx, cancel := context.WithTimeout(ctx, c.treeTimeout)
846846
defer cancel()
847847

848848
req.Path = strings.TrimPrefix(req.Path, "/")
@@ -912,7 +912,7 @@ func (c *Client) GetLogsTree(ctx context.Context, req types.GetLogsTreeRequest)
912912

913913
func (c *Client) GetRepoAllFiles(ctx context.Context, req gitserver.GetRepoAllFilesReq) ([]*types.File, error) {
914914
var files []*types.File
915-
ctx, cancel := context.WithTimeout(ctx, time.Second*3)
915+
ctx, cancel := context.WithTimeout(ctx, c.treeTimeout)
916916
defer cancel()
917917

918918
relativePath, err := c.BuildRelativePath(ctx, req.RepoType, req.Namespace, req.Name)
@@ -955,7 +955,7 @@ func (c *Client) GetRepoAllFiles(ctx context.Context, req gitserver.GetRepoAllFi
955955

956956
func (c *Client) GetRepoAllLfsPointers(ctx context.Context, req gitserver.GetRepoAllFilesReq) ([]*types.LFSPointer, error) {
957957
var pointers []*types.LFSPointer
958-
ctx, cancel := context.WithTimeout(ctx, time.Second*3)
958+
ctx, cancel := context.WithTimeout(ctx, c.treeTimeout)
959959
defer cancel()
960960

961961
relativePath, err := c.BuildRelativePath(ctx, req.RepoType, req.Namespace, req.Name)

common/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ type Config struct {
386386
LfsExistsCheck bool `env:"STARHUB_SERVER_GIT_LFS_EXISTS_CHECK" default:"true"`
387387
RepoDataMigrateEnable bool `env:"STARHUB_SERVER_GIT_REPO_DATA_MIGRATE_ENABLE" default:"false"`
388388
LimitLfsFileUploadSize bool `env:"STARHUB_SERVER_GIT_LIMIT_LFS_FILE_UPLOAD_SIZE " default:"true"`
389+
TreeOperationTimeout int `env:"STARHUB_SERVER_GIT_TREE_OPERATION_TIMEOUT" default:"3"`
389390
}
390391

391392
AIGateway struct {

0 commit comments

Comments
 (0)