From efb4eb984a445f38f4c054a34173b9231d2b1782 Mon Sep 17 00:00:00 2001 From: Brendan Kellam Date: Sun, 20 Jul 2025 11:59:15 -0700 Subject: [PATCH] fix(gitlab): Add configurable query timeout to GitLab client (#390) * fix * changelog --- CHANGELOG.md | 3 +++ docs/docs/configuration/environment-variables.mdx | 1 + docs/docs/connections/gitlab.mdx | 4 ++++ packages/backend/src/env.ts | 2 ++ packages/backend/src/gitlab.ts | 1 + 5 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7d8143e..55d8f253 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Relicense core to FSL-1.1-ALv2. [#388](https://github.com/sourcebot-dev/sourcebot/pull/388) +### Added +- Added `GITLAB_CLIENT_QUERY_TIMEOUT_SECONDS` env var to configure the GitLab client's query timeout. [#390](https://github.com/sourcebot-dev/sourcebot/pull/390) + ## [4.5.2] - 2025-07-19 ### Changed diff --git a/docs/docs/configuration/environment-variables.mdx b/docs/docs/configuration/environment-variables.mdx index e8fe8cf0..d6aab9eb 100644 --- a/docs/docs/configuration/environment-variables.mdx +++ b/docs/docs/configuration/environment-variables.mdx @@ -27,6 +27,7 @@ The following environment variables allow you to configure your Sourcebot deploy | `REDIS_REMOVE_ON_COMPLETE` | `0` |

Controls how many completed jobs are allowed to remain in Redis queues

| | `REDIS_REMOVE_ON_FAIL` | `100` |

Controls how many failed jobs are allowed to remain in Redis queues

| | `REPO_SYNC_RETRY_BASE_SLEEP_SECONDS` | `60` |

The base sleep duration (in seconds) for exponential backoff when retrying repository sync operations that fail

| +| `GITLAB_CLIENT_QUERY_TIMEOUT_SECONDS` | `600` |

The timeout duration (in seconds) for GitLab client queries

| | `SHARD_MAX_MATCH_COUNT` | `10000` |

The maximum shard count per query

| | `SMTP_CONNECTION_URL` | `-` |

The url to the SMTP service used for sending transactional emails. See [this doc](/docs/configuration/transactional-emails) for more info.

| | `SOURCEBOT_ENCRYPTION_KEY` | Automatically generated at startup if no value is provided. Generated using `openssl rand -base64 24` |

Used to encrypt connection secrets and generate API keys.

| diff --git a/docs/docs/connections/gitlab.mdx b/docs/docs/connections/gitlab.mdx index d0131e50..2677a67a 100644 --- a/docs/docs/connections/gitlab.mdx +++ b/docs/docs/connections/gitlab.mdx @@ -175,6 +175,10 @@ To connect to a GitLab host other than `gitlab.com`, provide the `url` property } ``` +## Troubleshooting + +- If you're seeing errors like `GitbeakerTimeoutError: Query timeout was reached` when syncing a large number of projects, you can increase the client's timeout by setting the `GITLAB_CLIENT_QUERY_TIMEOUT_SECONDS` environment variable. [#162](https://github.com/sourcebot-dev/sourcebot/issues/162) + ## Schema reference diff --git a/packages/backend/src/env.ts b/packages/backend/src/env.ts index 6a97db21..735361a8 100644 --- a/packages/backend/src/env.ts +++ b/packages/backend/src/env.ts @@ -49,6 +49,8 @@ export const env = createEnv({ CONNECTION_MANAGER_UPSERT_TIMEOUT_MS: numberSchema.default(300000), REPO_SYNC_RETRY_BASE_SLEEP_SECONDS: numberSchema.default(60), + + GITLAB_CLIENT_QUERY_TIMEOUT_SECONDS: numberSchema.default(60 * 10), }, runtimeEnv: process.env, emptyStringAsUndefined: true, diff --git a/packages/backend/src/gitlab.ts b/packages/backend/src/gitlab.ts index f08b4218..79ab643b 100644 --- a/packages/backend/src/gitlab.ts +++ b/packages/backend/src/gitlab.ts @@ -29,6 +29,7 @@ export const getGitLabReposFromConfig = async (config: GitlabConnectionConfig, o ...(config.url ? { host: config.url, } : {}), + queryTimeout: env.GITLAB_CLIENT_QUERY_TIMEOUT_SECONDS * 1000, }); let allRepos: ProjectSchema[] = [];