diff options
| author | radhitya <alif@radhitya.org> | 2026-06-22 20:11:01 +0700 |
|---|---|---|
| committer | radhitya <alif@radhitya.org> | 2026-06-22 20:11:01 +0700 |
| commit | 7f57333518ba0905d4447f7cd679ab018bfa12a7 (patch) | |
| tree | 79bf3904ffad2ddd129a026d4e9915c62c0f8f49 /internal/server | |
| parent | 81661cc8deaacbff3497f0c9ef2625e98257ef76 (diff) | |
fix bug and makefile
Diffstat (limited to 'internal/server')
| -rw-r--r-- | internal/server/server.go | 36 |
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 } |
