From 7f57333518ba0905d4447f7cd679ab018bfa12a7 Mon Sep 17 00:00:00 2001 From: radhitya Date: Mon, 22 Jun 2026 20:11:01 +0700 Subject: fix bug and makefile --- internal/server/server.go | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'internal/server/server.go') 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 } -- cgit v1.2.3