Skip to content

feat: add a reconnect to the initial ldap connection#928

Merged
steveiliop56 merged 5 commits into
mainfrom
feat/ldap-reconnect
Jun 30, 2026
Merged

feat: add a reconnect to the initial ldap connection#928
steveiliop56 merged 5 commits into
mainfrom
feat/ldap-reconnect

Conversation

@steveiliop56

@steveiliop56 steveiliop56 commented Jun 8, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes
    • Improved LDAP startup reliability by adding a brief timed retry before surfacing a connection error.
    • Made heartbeat recovery more resilient during intermittent LDAP outages, enabling smoother reconnection.
    • Refreshed reconnect behavior to respect the service’s active runtime context and to use an interval-based exponential retry strategy, reducing transient reconnect failures.
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jun 8, 2026
@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: ffa84c34-61e2-4878-a076-729b48e30904

📥 Commits

Reviewing files that changed from the base of the PR and between b93cd05 and 2482259.

📒 Files selected for processing (1)
  • internal/service/ldap_service.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/service/ldap_service.go

📝 Walkthrough

Walkthrough

LdapService now accepts an injected context.Context, stores it for reconnect retries, and uses interval-based reconnects on startup and heartbeat failures. The reconnect helper now uses the stored context, configurable backoff, and conditional connection cleanup.

Changes

LDAP reconnect & context wiring

Layer / File(s) Summary
LdapService ctx field and constructor wiring
internal/service/ldap_service.go
Adds ctx context.Context to LdapService, adds Ctx context.Context to LdapServiceInput, and assigns it in NewLdapService.
Startup and heartbeat reconnect call sites
internal/service/ldap_service.go
On initial connect() failure, calls reconnect(3s); heartbeat failure now calls reconnect(1s) instead of the no-argument form.
Reconnect implementation refactor
internal/service/ldap_service.go
reconnect accepts interval time.Duration, configures backoff initial interval from it, retries via ldap.ctx, and conditionally closes ldap.conn only when non-nil.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 A context hopped in with a tidy new name,
The reconnect learned intervals just the same.
Three seconds at startup, one on the beat,
Backoff now bounds with a gentler repeat,
And the ldap conn stays safe in the stream.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding a reconnect attempt when the initial LDAP connection fails.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/ldap-reconnect

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/service/ldap_service.go 0.00% 8 Missing ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/service/ldap_service.go`:
- Around line 66-70: The startup blocking retry in ldap_service.go (the call to
ldap.reconnect(...) inside the error branch after connection attempt) causes
~47.5s delay; either remove this startup reconnect entirely so setup continues
on LDAP failure (relying on existing heartbeat reconnect logic), or drastically
shorten it (e.g., call ldap.reconnect with a single short interval / 1–2 second
attempts or implement max 1-2 retries) and update the comment to reflect the
actual delay; locate the error handling around ldap.reconnect and adjust the
call and/or comment accordingly so BootstrapApp.setupServices will not block for
~47.5s when LDAP is unavailable.
- Around line 67-69: The logic in NewLdapService incorrectly returns nil even
when ldap.reconnect succeeds: adjust the error handling in the initial connect
branch (where err != nil) to call ldap.reconnect(10 * time.Second) and check its
return error; if reconnect returns nil then return the ldap pointer and nil
error, otherwise return nil and the wrapped reconnect error (fmt.Errorf("failed
to connect to ldap server: %w", err)). Ensure you reference the ldap variable
created in NewLdapService and only return nil when reconnect actually fails.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 90ca0a54-2e80-4d2f-8a87-9283a697d90d

📥 Commits

Reviewing files that changed from the base of the PR and between 426eac2 and ab6a2b4.

📒 Files selected for processing (1)
  • internal/service/ldap_service.go
Comment thread internal/service/ldap_service.go Outdated
Comment thread internal/service/ldap_service.go
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Jun 8, 2026
scottmckendry
scottmckendry previously approved these changes Jun 29, 2026
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jun 29, 2026
@steveiliop56 steveiliop56 merged commit ffafb5b into main Jun 30, 2026
5 checks passed
@steveiliop56 steveiliop56 deleted the feat/ldap-reconnect branch June 30, 2026 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.

2 participants