From 293a2b11cd7ebc142367a3943ba35b1a49c543cc Mon Sep 17 00:00:00 2001 From: David Crawshaw Date: Tue, 18 May 2021 13:25:43 -0700 Subject: [PATCH 1/2] ipn: allow b to be nil in NewBackendServer A couple of code paths in ipnserver use a NewBackendServer with a nil backend just to call the callback with an encapsulated error message. This covers a panic case seen in logs. For #1920 Signed-off-by: David Crawshaw --- ipn/message.go | 4 +++- ipn/message_test.go | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ipn/message.go b/ipn/message.go index d8b7d1396..fb5638eca 100644 --- a/ipn/message.go +++ b/ipn/message.go @@ -104,7 +104,9 @@ func NewBackendServer(logf logger.Logf, b Backend, sendNotifyMsg func(Notify)) * b: b, sendNotifyMsg: sendNotifyMsg, } - if sendNotifyMsg != nil { + // b may be nil if the BackendServer is being created just to + // encapsulate and send an error message. + if sendNotifyMsg != nil && b != nil { b.SetNotifyCallback(bs.send) } return bs diff --git a/ipn/message_test.go b/ipn/message_test.go index 79c4a76b6..194ac3b89 100644 --- a/ipn/message_test.go +++ b/ipn/message_test.go @@ -187,3 +187,17 @@ func TestClientServer(t *testing.T) { }) flushUntil(Running) } + +func TestNilBackend(t *testing.T) { + var called *Notify + bs := NewBackendServer(t.Logf, nil, func(n Notify) { + called = &n + }) + bs.SendErrorMessage("Danger, Will Robinson!") + if called == nil { + t.Errorf("expect callback to be called, wasn't") + } + if called.ErrMessage == nil || *called.ErrMessage != "Danger, Will Robinson!" { + t.Errorf("callback got wrong error: %v", called.ErrMessage) + } +} From cd54792fe92d3df5b02f8d8363f57e10082ad14a Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Tue, 18 May 2021 08:51:46 -0700 Subject: [PATCH 2/2] internal/deephash: add a few more benchmarking map entries Typical maps in production are considerably longer. This helps benchmarks more accurately reflect the costs per key vs the costs per map in deephash. Signed-off-by: Josh Bleecher Snyder --- internal/deephash/deephash_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/deephash/deephash_test.go b/internal/deephash/deephash_test.go index d99612adc..3d33bcd4a 100644 --- a/internal/deephash/deephash_test.go +++ b/internal/deephash/deephash_test.go @@ -51,14 +51,23 @@ func getVal() []interface{} { map[dnsname.FQDN][]netaddr.IP{ dnsname.FQDN("a."): {netaddr.MustParseIP("1.2.3.4"), netaddr.MustParseIP("4.3.2.1")}, dnsname.FQDN("b."): {netaddr.MustParseIP("8.8.8.8"), netaddr.MustParseIP("9.9.9.9")}, + dnsname.FQDN("c."): {netaddr.MustParseIP("6.6.6.6"), netaddr.MustParseIP("7.7.7.7")}, + dnsname.FQDN("d."): {netaddr.MustParseIP("6.7.6.6"), netaddr.MustParseIP("7.7.7.8")}, + dnsname.FQDN("e."): {netaddr.MustParseIP("6.8.6.6"), netaddr.MustParseIP("7.7.7.9")}, + dnsname.FQDN("f."): {netaddr.MustParseIP("6.9.6.6"), netaddr.MustParseIP("7.7.7.0")}, }, map[dnsname.FQDN][]netaddr.IPPort{ dnsname.FQDN("a."): {netaddr.MustParseIPPort("1.2.3.4:11"), netaddr.MustParseIPPort("4.3.2.1:22")}, dnsname.FQDN("b."): {netaddr.MustParseIPPort("8.8.8.8:11"), netaddr.MustParseIPPort("9.9.9.9:22")}, + dnsname.FQDN("c."): {netaddr.MustParseIPPort("8.8.8.8:12"), netaddr.MustParseIPPort("9.9.9.9:23")}, + dnsname.FQDN("d."): {netaddr.MustParseIPPort("8.8.8.8:13"), netaddr.MustParseIPPort("9.9.9.9:24")}, + dnsname.FQDN("e."): {netaddr.MustParseIPPort("8.8.8.8:14"), netaddr.MustParseIPPort("9.9.9.9:25")}, }, map[tailcfg.DiscoKey]bool{ {1: 1}: true, {1: 2}: false, + {2: 3}: true, + {3: 4}: false, }, } }