fix: remove hidden global state

dns.HandleFunc(".", handler) modifies the global dns.DefaultServeMux and
dns.Server uses that if it is initialized without a Handler. This would
cause issues when multiple instances of the module try to Present() at
the same time.
This commit is contained in:
xaos 2023-02-28 13:19:29 +01:00
parent 769d017d22
commit 71d1f19169

View file

@ -116,9 +116,12 @@ func (s *StubDNS) Present(ctx context.Context, challenge acme.Challenge) error {
// spawn the server
handler := s.make_handler(fqdn, content)
// could also use fqdn as pattern, but "." allows logging invalid requests
dns.HandleFunc(".", handler)
server := &dns.Server{Addr: s.Address, Net: "udp", TsigSecret: nil}
server := &dns.Server{
Addr: s.Address,
Net: "udp",
Handler: handler,
TsigSecret: nil,
}
go s.serve(server)
// store the server for shutdown later