Skip to content

Commit

Permalink
net/dns: fix crash in tests
Browse files Browse the repository at this point in the history
Looks like #12346 as submitted with failing tests.

Updates #12346

Change-Id: I582cd0dfb117686330d935d763d972373c5ae598
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
  • Loading branch information
bradfitz committed Jun 7, 2024
1 parent 0219317 commit 916c4db
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 5 additions & 3 deletions net/dns/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ type Manager struct {

resolver *resolver.Resolver
os OSConfigurator
knobs *controlknobs.Knobs
goos string // if empty, gets set to runtime.GOOS
knobs *controlknobs.Knobs // or nil
goos string // if empty, gets set to runtime.GOOS
}

// NewManagers created a new manager from the given config.
//
// knobs may be nil.
func NewManager(logf logger.Logf, oscfg OSConfigurator, health *health.Tracker, dialer *tsdial.Dialer, linkSel resolver.ForwardLinkSelector, knobs *controlknobs.Knobs, goos string) *Manager {
if dialer == nil {
panic("nil Dialer")
Expand Down Expand Up @@ -296,7 +298,7 @@ func (m *Manager) compileConfig(cfg Config) (rcfg resolver.Config, ocfg OSConfig
}

func (m *Manager) disableSplitDNSOptimization() bool {
return m.knobs.DisableSplitDNSWhenNoCustomResolvers.Load()
return m.knobs != nil && m.knobs.DisableSplitDNSWhenNoCustomResolvers.Load()
}

// toIPsOnly returns only the IP portion of dnstype.Resolver.
Expand Down
5 changes: 4 additions & 1 deletion net/dns/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"tailscale.com/control/controlknobs"
"tailscale.com/health"
"tailscale.com/net/dns/resolver"
"tailscale.com/net/netmon"
"tailscale.com/net/tsdial"
Expand Down Expand Up @@ -858,7 +860,8 @@ func TestManager(t *testing.T) {
if goos == "" {
goos = "linux"
}
m := NewManager(t.Logf, &f, nil, tsdial.NewDialer(netmon.NewStatic()), nil, nil, goos)
knobs := &controlknobs.Knobs{}
m := NewManager(t.Logf, &f, new(health.Tracker), tsdial.NewDialer(netmon.NewStatic()), nil, knobs, goos)
m.resolver.TestOnlySetHook(f.SetResolver)

if err := m.Set(test.in); err != nil {
Expand Down

0 comments on commit 916c4db

Please sign in to comment.