summaryrefslogtreecommitdiff
path: root/internal/server
diff options
context:
space:
mode:
Diffstat (limited to 'internal/server')
-rw-r--r--internal/server/server.go36
1 files changed, 21 insertions, 15 deletions
diff --git a/internal/server/server.go b/internal/server/server.go
index 74add95..7bdc917 100644
--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -39,6 +39,7 @@ type Server struct {
upDoH bool
upDoT bool
cancel context.CancelFunc
+ closeOnce sync.Once
}
func (s *Server) Ready() bool {
@@ -180,12 +181,15 @@ func (s *Server) Run(ctx context.Context) error {
if s.udp != nil {
s.udp.Shutdown(shutdownCtx)
+ s.udp = nil
}
if s.tcp != nil {
s.tcp.Shutdown(shutdownCtx)
+ s.tcp = nil
}
if s.doh != nil {
s.doh.Shutdown(shutdownCtx)
+ s.doh = nil
}
return ctx.Err()
case err := <-errCh:
@@ -194,21 +198,23 @@ func (s *Server) Run(ctx context.Context) error {
}
func (s *Server) Close() error {
- if s.admin != nil {
- s.admin.Close()
- }
- if s.udp != nil {
- s.udp.Shutdown(context.Background())
- }
- if s.tcp != nil {
- s.tcp.Shutdown(context.Background())
- }
- if s.dot != nil {
- s.dot.Shutdown(context.Background())
- }
- if s.doh != nil {
- s.doh.Close()
- }
+ s.closeOnce.Do(func() {
+ if s.admin != nil {
+ s.admin.Close()
+ }
+ if s.udp != nil {
+ s.udp.Shutdown(context.Background())
+ }
+ if s.tcp != nil {
+ s.tcp.Shutdown(context.Background())
+ }
+ if s.dot != nil {
+ s.dot.Shutdown(context.Background())
+ }
+ if s.doh != nil {
+ s.doh.Close()
+ }
+ })
return nil
}