Skip to content

fix: defer default bootstrap DNS resolution to first tick#92

Open
afterburn wants to merge 1 commit intomainfrom
fix/219
Open

fix: defer default bootstrap DNS resolution to first tick#92
afterburn wants to merge 1 commit intomainfrom
fix/219

Conversation

@afterburn
Copy link
Contributor

Dht::new() spawns an actor thread that runs Rpc::new(), then blocks waiting for it to signal ready. When no custom bootstrap nodes are configured, Rpc::new() synchronously resolves the 4 default bootstrap hostnames via to_socket_addrs(). On systems with slow DNS this can take several seconds, stalling the caller of Dht::new().

The fix stores the default bootstrap hostnames unresolved during Rpc::new() and defers DNS resolution to the first tick() call in populate(). Since tick() runs on the actor thread after signaling ready, Dht::new() now returns as fast as the UDP socket can bind. Pre-resolved bootstrap nodes passed via DhtBuilder::bootstrap() are unaffected.

Fixes pubky/pkarr#219

@afterburn afterburn requested a review from 86667 March 6, 2026 21:09
///
/// Reset the last_table_refresh timer.
fn resolve_pending_bootstrap(&mut self) {
if let Some(hostnames) = self.unresolved_bootstrap.take() {
Copy link

@86667 86667 Mar 9, 2026

Choose a reason for hiding this comment

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

take() means this only runs once. Is there a scenario in which we may want to retry? i think maybe and not costly to clone instead

Copy link

@86667 86667 left a comment

Choose a reason for hiding this comment

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

Looks good apart from lack of retry, i guess this is not a regression on existing behaviour though

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.

Creating the Client is kind of slow

2 participants