Skip to content

Conversation

@jingglypuff
Copy link
Contributor

@jingglypuff jingglypuff commented Sep 26, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Reduced intermittent failures when fetching data from ServiceNow by adding automatic retries with exponential backoff on transient timeouts.
  • Chores
    • Increased default HTTP client timeout to 10 minutes to better accommodate long-running requests.

@coderabbitai
Copy link

coderabbitai bot commented Sep 26, 2025

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly references the two primary changes—extending the HTTP timeout and introducing retry behavior—and is clearly related to the content of the PR.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jh/DUCT-12594-timeout

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
pkg/servicenow/client.go (1)

604-606: Respect context cancellation during backoff waits.

time.Sleep ignores ctx cancel/deadline signals, so a canceled sync still waits the full backoff interval (up to 6s here) before honoring the cancellation. Please gate the sleep with a select on ctx.Done() (same change for each retry loop).

A possible update:

-					delay := baseDelay * time.Duration(1<<attempt)
-					time.Sleep(delay)
+					delay := baseDelay * time.Duration(1<<attempt)
+					select {
+					case <-time.After(delay):
+					case <-ctx.Done():
+						return nil, "", ctx.Err()
+					}

Also applies to: 639-641, 672-674

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7c7d2d6 and f014f9e.

📒 Files selected for processing (2)
  • pkg/connector/connector.go (2 hunks)
  • pkg/servicenow/client.go (4 hunks)
🧰 Additional context used
🪛 GitHub Check: go-lint
pkg/connector/connector.go

[failure] 124-124:
File is not properly formatted (goimports)

pkg/servicenow/client.go

[failure] 598-598:
File is not properly formatted (goimports)

🪛 GitHub Actions: ci
pkg/connector/connector.go

[error] 124-124: golangci-lint: File is not properly formatted (goimports). Run 'goimports -w' or 'gofmt -w' to fix formatting.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Cursor Bugbot

Comment on lines +124 to 126

httpClient.Timeout = 10 * time.Minute

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Fix gofmt/goimports formatting before merging.

CI failed because this file is not gofmt/goimports formatted. Please run goimports -w pkg/connector/connector.go (or gofmt) and re-push so the pipeline passes.

🧰 Tools
🪛 GitHub Check: go-lint

[failure] 124-124:
File is not properly formatted (goimports)

🪛 GitHub Actions: ci

[error] 124-124: golangci-lint: File is not properly formatted (goimports). Run 'goimports -w' or 'gofmt -w' to fix formatting.

🤖 Prompt for AI Agents
In pkg/connector/connector.go around lines 124 to 126, the file is not formatted
with gofmt/goimports which breaks CI; run goimports -w
pkg/connector/connector.go (or gofmt -w pkg/connector/connector.go), ensure
imports are organized and the file is saved, then re-commit and push the change
so the pipeline can pass.

Comment on lines +599 to +609
for attempt := 0; attempt < maxRetries; attempt++ {
next, err := c.get(ctx, fmt.Sprintf(VariableSetM2MBaseUrl, c.deployment), &resp, req...)
if err != nil {
if status.Code(err) == codes.DeadlineExceeded || strings.Contains(err.Error(), "timeout") || strings.Contains(err.Error(), "deadline exceeded") {
if attempt < maxRetries-1 {
delay := baseDelay * time.Duration(1<<attempt)
time.Sleep(delay)
continue
}
}
return nil, "", err
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Retry condition misses HTTP gateway/request timeouts.

doRequest wraps HTTP failures with status.Error(codes.Code(status), "Request failed"). For 504/408 responses, status.Code(err) becomes codes.Code(504)/codes.Code(408) and the message lacks "timeout" wording, so these new retries never trigger and we still fail immediately on the common ServiceNow timeout scenarios. Please treat those HTTP statuses as retryable (and apply the fix to all three functions).

Apply this diff (pattern repeated in the other two retry blocks):

-		if err != nil {
-			if status.Code(err) == codes.DeadlineExceeded || strings.Contains(err.Error(), "timeout") || strings.Contains(err.Error(), "deadline exceeded") {
+		if err != nil {
+			code := status.Code(err)
+			if code == codes.DeadlineExceeded ||
+				code == codes.Code(http.StatusGatewayTimeout) ||
+				code == codes.Code(http.StatusRequestTimeout) ||
+				strings.Contains(err.Error(), "timeout") ||
+				strings.Contains(err.Error(), "deadline exceeded") {

Also applies to: 634-644, 667-677

🤖 Prompt for AI Agents
In pkg/servicenow/client.go around lines 599-609 (and similarly apply to 634-644
and 667-677): the retry condition only checks for gRPC DeadlineExceeded or text
containing "timeout"/"deadline exceeded", but doRequest wraps HTTP 504/408
responses into status.Errors with numeric codes (e.g. codes.Code(504),
codes.Code(408)) and no "timeout" text, so those timeouts never trigger a retry.
Update the conditional to also treat HTTP 504 and 408 as retryable by checking
status.Code(err) against codes.Code(504) and codes.Code(408) (in addition to
codes.DeadlineExceeded and the existing string checks), then keep the existing
exponential backoff and continue logic; apply the same change to the two other
retry blocks at the specified lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants