You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A shared rdap.Client races on lazy init, the bootstrap Verbose swap and the bootstrap registry map, and can panic under concurrent Do calls. This adds a mutex to Client and bootstrap.Client, and makes Request.URL() copy the server URL instead of modifying it in place. Includes a test that runs concurrent Do calls against a shared client under -race.
Summary by CodeRabbit
New Features
Bootstrap lookups can now accept a per-call verbose callback, allowing callers to receive lookup details without changing the shared client’s callback setting.
Bug Fixes
Improved reliability when multiple requests use the same client concurrently, including requests that rely on bootstrap lookup.
Fixed URL construction so existing server query parameters and fragments are preserved when building a domain request URL.
Client operations now lock shared initialization, bootstrap registry, and cache state. Bootstrap lookups accept per-call verbose callbacks without changing the shared callback. Request.URL copies the server URL before building the request URL. New tests cover concurrent requests, bootstrap lookups, and preservation of the server URL query and fragment.
Severity of issue fixed: Medium
Merge Risk: Low · up to abf8f
The change makes the client safe for concurrent use and removes the earlier deadlock and stall risks. Concurrent lookups on a cold or just-refreshed cache may still download the same bootstrap file more than once. That adds some network traffic but does not produce wrong results, so this is acceptable with owner awareness.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
Title fits the main change. PR makes Client safe for concurrent use. Changes add mutexes to Client and bootstrap.Client, add LookupVerbose, fix Request.URL to copy server URL, and add concurrency test…
Linked Issues check
[#31] Requirement: make client.Do() safe for concurrent use, or document the limit.
Source read at head (not only summary): - client.go: Client has mu sync.Mutex. Do() takes mu only while it sets def…
Out of Scope Changes check
All production changes serve the concurrency objective of #31: - client.go: mutex around lazy init and Verbose selection. Verbose swap on shared bootstrap client removed. - bootstrap/client.go: mutex …
Full details: Title check
Explanation
Title fits the main change. PR makes Client safe for concurrent use. Changes add mutexes to Client and bootstrap.Client, add LookupVerbose, fix Request.URL to copy server URL, and add concurrency tests. Linked issue #31 asks for the same thing. Title is short, specific, and clear.
Full details: Linked Issues check
Explanation
[#31] Requirement: make client.Do() safe for concurrent use, or document the limit.
Source read at head (not only summary):
client.go: Client has mu sync.Mutex. Do() takes mu only while it sets defaults for HTTP, Bootstrap, and Verbose. Verbose is no longer swapped on the shared bootstrap client. Do() calls c.Bootstrap.LookupVerbose(question, c.Verbose), which removes the old race on shared Verbose state (the reported client.go:96 write).
bootstrap/client.go: Client has mu sync.Mutex guarding init, registries map, Cache state, and reloadFromCache. Downloads run without mu (downloadAndStore), then store under mu. Verbose is never called with mu held. This removes the reported map race in Lookup (bootstrap/client.go:340 path).
request.go: URL() copies *r.Server into tempURL and clears RawQuery/Fragment on the copy. Query() returns a new map and does not mutate the shared Server. This removes the shared-pointer write.
Not verified: test files (client_concurrency_test.go, bootstrap/concurrency_test.go) were not read. Test pass and -race results were not run. The PASS rests on source of the three production files. Issue #31 does not require a test, so this does not change the verdict.
Full details: Out of Scope Changes check
Explanation
All production changes serve the concurrency objective of #31:
client.go: mutex around lazy init and Verbose selection. Verbose swap on shared bootstrap client removed.
bootstrap/client.go: mutex around registry map, cache access, and lazy init. New exported LookupVerbose(question, verbose) is the per-call callback that replaces the shared Verbose swap. It is a direct part of the fix. Lookup now delegates to it with nil. Exported API addition is a necessary consequence of the fix, not unrelated scope.
request.go: URL() copy fix. Raw-request branch is unchanged in behavior.
No unrelated feature or behavior change seen. Test files were not read directly, so their content is judged from summary only. Supporting tests for this fix are in scope.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 164aaf14-c1e8-48db-afb4-e7aaf7f55570
Commits
Reviewing files that changed from the base of the PR and between 64c8c7d and b884322.
Files selected for processing: 4
bootstrap/client.go
client.go
client_concurrency_test.go
request.go
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Major · Stability & Availability · Heavy lift
Run Verbose callbacks outside the bootstrap mutex.
If b.Verbose calls b.DNS(), b.Lookup() now deadlocks. Lookup holds b.mu when it invokes Verbose. DNS then waits for the same mutex. Before this change, that callback returned normally.
Capture the needed state under the mutex. Release the mutex before invoking caller callbacks.
The reason will be displayed to describe this comment to others. Learn more.
Major · Stability & Availability · Heavy lift
Do not hold the client mutex across bootstrap network I/O.
If one bootstrap download stalls, this mutex blocks every later Do, including requests with an explicit server. Those requests wait at Line 112. An expired request context cannot release that wait. The default HTTP client has no timeout, so the wait can outlast the 30-second doQuickRequest timeout indefinitely.
Release state locks before network I/O. Address the bootstrap mutex held across the download too. Make required waiting context-aware.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: d0378976-d005-4b2e-bb68-daf8ef7f0aa7
Commits
Reviewing files that changed from the base of the PR and between b884322 and abf8f98.
Files selected for processing: 4
bootstrap/client.go
bootstrap/concurrency_test.go
client.go
client_concurrency_test.go
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Performance & Scalability · Quick win
Recheck expiry before starting a refresh.
Caller A can record Expired, then pause in the verbose callback. Caller B can refresh the registry during that pause. When A resumes, its old forceDownload=true still forces another download despite the fresh registry.
Recheck cache state under mu before the download decision. Keep cache-load failure as a separate refresh reason. This avoids a second network wait after a successful refresh.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Performance & Scalability · Heavy lift
Share one in-flight refresh per registry.
With an empty cache, all 16 concurrent lookups can pass Line 384 before any download completes. Each then downloads the same registry. Bootstrap traffic grows with request concurrency. This violates the documented once-per-24-hours cache behavior. (raw.githubusercontent.com)
Reserve the registry refresh under mu. Let other callers wait outside mu, with their own contexts. Clear the reservation on success and failure. Add a concurrent cold-cache test that counts bootstrap requests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #31
A shared
rdap.Clientraces on lazy init, the bootstrapVerboseswap and the bootstrap registry map, and can panic under concurrentDocalls. This adds a mutex toClientandbootstrap.Client, and makesRequest.URL()copy the server URL instead of modifying it in place. Includes a test that runs concurrentDocalls against a shared client under-race.Summary by CodeRabbit