wait blocks until the TXT record created in Present() appears in authoritative lookups, i.e. until it has propagated, or until timeout, whichever is first.
(ctx context.Context, zrec zoneRecord)
| 417 | // authoritative lookups, i.e. until it has propagated, or until |
| 418 | // timeout, whichever is first. |
| 419 | func (m *DNSManager) wait(ctx context.Context, zrec zoneRecord) error { |
| 420 | logger := m.logger() |
| 421 | |
| 422 | // if configured to, pause before doing propagation checks |
| 423 | // (even if they are disabled, the wait might be desirable on its own) |
| 424 | if m.PropagationDelay > 0 { |
| 425 | select { |
| 426 | case <-time.After(m.PropagationDelay): |
| 427 | case <-ctx.Done(): |
| 428 | return ctx.Err() |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | // skip propagation checks if configured to do so |
| 433 | if m.PropagationTimeout == -1 { |
| 434 | return nil |
| 435 | } |
| 436 | |
| 437 | // timings |
| 438 | timeout := m.PropagationTimeout |
| 439 | if timeout == 0 { |
| 440 | timeout = defaultDNSPropagationTimeout |
| 441 | } |
| 442 | const interval = 2 * time.Second |
| 443 | |
| 444 | // how we'll do the checks |
| 445 | checkAuthoritativeServers := len(m.Resolvers) == 0 |
| 446 | resolvers := RecursiveNameservers(m.Resolvers) |
| 447 | |
| 448 | rr := zrec.record.RR() |
| 449 | recType := dns.TypeTXT |
| 450 | if rr.Type == "CNAME" { |
| 451 | recType = dns.TypeCNAME |
| 452 | } |
| 453 | |
| 454 | absName := libdns.AbsoluteName(rr.Name, zrec.zone) |
| 455 | |
| 456 | var err error |
| 457 | start := time.Now() |
| 458 | for time.Since(start) < timeout { |
| 459 | select { |
| 460 | case <-time.After(interval): |
| 461 | case <-ctx.Done(): |
| 462 | return ctx.Err() |
| 463 | } |
| 464 | |
| 465 | logger.Debug("checking DNS propagation", |
| 466 | zap.String("fqdn", absName), |
| 467 | zap.String("record_type", rr.Type), |
| 468 | zap.String("expected_data", rr.Data), |
| 469 | zap.Strings("resolvers", resolvers)) |
| 470 | |
| 471 | var ready bool |
| 472 | ready, err = checkDNSPropagation(ctx, logger, absName, recType, rr.Data, checkAuthoritativeServers, resolvers) |
| 473 | if err != nil { |
| 474 | return fmt.Errorf("checking DNS propagation of %q (relative=%s zone=%s resolvers=%v): %w", absName, rr.Name, zrec.zone, resolvers, err) |
| 475 | } |
| 476 | if ready { |
no test coverage detected