summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-06-24 22:14:19 +0700
committerShulhan <ms@kilabit.info>2022-06-24 22:14:19 +0700
commit9bb1e57d4a8f499784e83bc63f1ded6ad21f218d (patch)
treeef0d4203ca5bee2fa9d2d7702bdb48f236ae3e7c
parent25a9b45517225b09039cfb7ef887e5db3bb8ebbc (diff)
downloadpakakeh.go-9bb1e57d4a8f499784e83bc63f1ded6ad21f218d.tar.xz
lib/dns: use Shutdown to stop DoH server
Using Shutdown allow active connection not interrupted but it may cause delay when restarting the server. While at it, set the doh and dot server instance to nil to release the resource, in case the Server need to start again.
-rw-r--r--lib/dns/server.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/dns/server.go b/lib/dns/server.go
index 21d6a2be..436dcaf5 100644
--- a/lib/dns/server.go
+++ b/lib/dns/server.go
@@ -5,6 +5,7 @@
package dns
import (
+ "context"
"crypto/tls"
"encoding/base64"
"errors"
@@ -217,12 +218,15 @@ func (srv *Server) Stop() {
if err != nil {
log.Println("dns: error when closing DoT: " + err.Error())
}
+ srv.dot = nil
}
if srv.doh != nil {
- err = srv.doh.Close()
+ var ctx context.Context = context.Background()
+ err = srv.doh.Shutdown(ctx)
if err != nil {
log.Println("dns: error when closing DoH: " + err.Error())
}
+ srv.doh = nil
}
}