Skip to content

Commit

Permalink
bootstrap: imp code
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizzick committed Jun 28, 2024
1 parent fba0288 commit fee9de8
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion internal/bootstrap/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bootstrap

import (
"context"
"log/slog"
"net"
"net/netip"
"slices"
Expand Down Expand Up @@ -67,10 +68,24 @@ func (r ParallelResolver) LookupNetIP(
return nil, errors.Join(errs...)
}

// recoverAndLog is a deferred helper that recovers from a panic and logs the
// panic value with the logger from context or with a default logger.
//
// TODO(d.kolyshev): Improve.
// TODO(a.garipov): Move this helper to golibs.
func recoverAndLog(ctx context.Context) {
l, ok := slogutil.LoggerFromContext(ctx)
if !ok {
l = slog.Default()
}

slogutil.RecoverAndLog(ctx, l)
}

// lookupAsync performs a lookup for ip of host with r and sends the result into
// resCh. It is intended to be used as a goroutine.
func lookupAsync(ctx context.Context, r Resolver, network, host string, resCh chan<- any) {
defer slogutil.RecoverAndLog(ctx, slogutil.NewDiscardLogger())
defer recoverAndLog(ctx)

addrs, err := lookup(ctx, r, network, host)
if err != nil {
Expand Down

0 comments on commit fee9de8

Please sign in to comment.