From b6053053b70cdfa9b60990bd3fb9e388b39fc21b Mon Sep 17 00:00:00 2001 From: Dev Agent Date: Tue, 30 Dec 2025 09:54:47 +0000 Subject: [PATCH] Add git tree operation timeout config --- builder/git/gitserver/gitaly/client.go | 3 +++ builder/git/gitserver/gitaly/file.go | 10 +++++----- common/config/config.go | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/builder/git/gitserver/gitaly/client.go b/builder/git/gitserver/gitaly/client.go index f0909a596..f3a70ae7c 100644 --- a/builder/git/gitserver/gitaly/client.go +++ b/builder/git/gitserver/gitaly/client.go @@ -33,6 +33,7 @@ type Client struct { smartHttpClient gitalypb.SmartHTTPServiceClient remoteClient gitalypb.RemoteServiceClient timeout time.Duration + treeTimeout time.Duration repoStore database.RepoStore } @@ -91,6 +92,7 @@ func NewClient(config *config.Config) (*Client, error) { } timeoutTime := time.Duration(config.Git.OperationTimeout) * time.Second + treeTimeoutTime := time.Duration(config.Git.TreeOperationTimeout) * time.Second return &Client{ config: config, sidechannelRegistry: sidechannelRegistry, @@ -104,5 +106,6 @@ func NewClient(config *config.Config) (*Client, error) { remoteClient: remoteClient, timeout: timeoutTime, repoStore: database.NewRepoStore(), + treeTimeout: treeTimeoutTime, }, nil } diff --git a/builder/git/gitserver/gitaly/file.go b/builder/git/gitserver/gitaly/file.go index 4c012e8cf..c404b2d5a 100644 --- a/builder/git/gitserver/gitaly/file.go +++ b/builder/git/gitserver/gitaly/file.go @@ -610,7 +610,7 @@ func (c *Client) getBlobInfo(ctx context.Context, repo *gitalypb.Repository, pat func (c *Client) GetRepoFileTree(ctx context.Context, req gitserver.GetRepoInfoByPathReq) ([]*types.File, error) { var files []*types.File - ctx, cancel := context.WithTimeout(ctx, time.Second*3) + ctx, cancel := context.WithTimeout(ctx, c.treeTimeout) defer cancel() req.Path = strings.TrimPrefix(req.Path, "/") @@ -757,7 +757,7 @@ func (c *Client) GetRepoFileTree(ctx context.Context, req gitserver.GetRepoInfoB } func (c *Client) GetTree(ctx context.Context, req types.GetTreeRequest) (*types.GetRepoFileTreeResp, error) { - ctx, cancel := context.WithTimeout(ctx, time.Second*3) + ctx, cancel := context.WithTimeout(ctx, c.treeTimeout) defer cancel() req.Path = strings.TrimPrefix(req.Path, "/") @@ -842,7 +842,7 @@ func (c *Client) GetTree(ctx context.Context, req types.GetTreeRequest) (*types. func (c *Client) GetLogsTree(ctx context.Context, req types.GetLogsTreeRequest) (*types.LogsTreeResp, error) { var resp []*types.CommitForTree - ctx, cancel := context.WithTimeout(ctx, time.Second*3) + ctx, cancel := context.WithTimeout(ctx, c.treeTimeout) defer cancel() req.Path = strings.TrimPrefix(req.Path, "/") @@ -912,7 +912,7 @@ func (c *Client) GetLogsTree(ctx context.Context, req types.GetLogsTreeRequest) func (c *Client) GetRepoAllFiles(ctx context.Context, req gitserver.GetRepoAllFilesReq) ([]*types.File, error) { var files []*types.File - ctx, cancel := context.WithTimeout(ctx, time.Second*3) + ctx, cancel := context.WithTimeout(ctx, c.treeTimeout) defer cancel() 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 func (c *Client) GetRepoAllLfsPointers(ctx context.Context, req gitserver.GetRepoAllFilesReq) ([]*types.LFSPointer, error) { var pointers []*types.LFSPointer - ctx, cancel := context.WithTimeout(ctx, time.Second*3) + ctx, cancel := context.WithTimeout(ctx, c.treeTimeout) defer cancel() relativePath, err := c.BuildRelativePath(ctx, req.RepoType, req.Namespace, req.Name) diff --git a/common/config/config.go b/common/config/config.go index 49eb383a0..6feb51489 100644 --- a/common/config/config.go +++ b/common/config/config.go @@ -386,6 +386,7 @@ type Config struct { LfsExistsCheck bool `env:"STARHUB_SERVER_GIT_LFS_EXISTS_CHECK" default:"true"` RepoDataMigrateEnable bool `env:"STARHUB_SERVER_GIT_REPO_DATA_MIGRATE_ENABLE" default:"false"` LimitLfsFileUploadSize bool `env:"STARHUB_SERVER_GIT_LIMIT_LFS_FILE_UPLOAD_SIZE " default:"true"` + TreeOperationTimeout int `env:"STARHUB_SERVER_GIT_TREE_OPERATION_TIMEOUT" default:"3"` } AIGateway struct {