StackExchange / dnscontrol

Infrastructure as code for DNS!
https://dnscontrol.org/
MIT License
3.07k stars 389 forks source link

Multiple TXT records in apex causes panic #28

Closed mhenderson-so closed 7 years ago

mhenderson-so commented 7 years ago

Having two apex TXT records causes a panic. e.g. the following config:

TXT('@','google-site-verification=abcd1234'),
TXT('@','google-site-verification=wxyz9876'),

causes panic:

panic: interface conversion: interface {} is nil, not *models.RecordConfig

goroutine 1 [running]:
panic(0xa0e120, 0xc0422be1c0)
        /usr/local/go/src/runtime/panic.go:500 +0x1af
github.com/StackExchange/dnscontrol/providers/namedotcom.(*nameDotCom).GetDomainCorrections(0xc0424d1420, 0xc04226c3f0, 0xc0426f17b0, 0xf, 0xc042380658, 0x1, 0x0)
        /go/src/github.com/StackExchange/dnscontrol/providers/namedotcom/records.go:44 +0x98c
main.main()
        /go/src/github.com/StackExchange/dnscontrol/main.go:184 +0x1051
captncraig commented 7 years ago

Almost certainly related to my recent re-factoring. Is this urgent?

mhenderson-so commented 7 years ago

Don't stress over it. Tom is looking into it, and they have a workaround.

tlimoncelli commented 7 years ago

I see the problem. It isn't related to apex records. There are 2 ways that a "create" Correlation is created in IncrementalDifff(). The 2nd one creates a RecordConfig with a nil .Origional, which confuses the namedotcom provider.

This is the code that generates the invalid Correlation:

providers/diff/diff.go

  for _, desiredList := range desiredByNameAndType {
    for _, rec := range desiredList {
      fmt.Printf("DEBUG rec: %v\n", rec.Original)
      // These rec's do not have a valid Desired.Original
      create = append(create, Correlation{d, nil, rec})
    }
  }

A hack like this will let "preview" pass, but then "push" fails:

                corrections = append(corrections, c)
        }
        for _, cre := range create {
-               rec := cre.Desired.Original.(*models.RecordConfig)
+               var rec *models.RecordConfig
+               if cre.Desired.Original != nil {
+                       rec = cre.Desired.Original.(*models.RecordConfig)
+               }
                c := &models.Correction{Msg: cre.String(), F: func() error { return n.createRecord(rec, dc.Name) }}