From 71d1f1916957cf1f33bf588181fce540f18ec24d Mon Sep 17 00:00:00 2001 From: xaos Date: Tue, 28 Feb 2023 13:19:29 +0100 Subject: [PATCH] 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. --- stub.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/stub.go b/stub.go index 8f420b9..56e01b8 100644 --- a/stub.go +++ b/stub.go @@ -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