From 2fdbe5c0ca19b5dfee494d285204e68eb93a0b7e Mon Sep 17 00:00:00 2001 From: zarazaex69 Date: Sat, 16 May 2026 18:22:02 +0300 Subject: [PATCH] fix(session): apply custom DNS before connect --- go.sum | 2 -- internal/app/session/session.go | 17 ++++++++++++++++- internal/server/server.go | 14 +++++++------- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/go.sum b/go.sum index bf58883..8c428f1 100644 --- a/go.sum +++ b/go.sum @@ -235,8 +235,6 @@ github.com/xtaci/smux v1.5.57/go.mod h1:IGQ9QYrBphmb/4aTnLEcJby0TNr3NV+OslIOMrX8 github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/zarazaex69/gr v0.0.0-20260430043628-45b595f4fef0 h1:dMjHX/YPV3ZD/KJKFjQdlMBwj2/rZIuOVKOvGv26m9k= github.com/zarazaex69/gr v0.0.0-20260430043628-45b595f4fef0/go.mod h1:7vALI2tjaLTOGiDKV7V2JkVU9bA1YADBDQA6uvpp1ac= -github.com/zarazaex69/j v0.0.0-20260515222039-806b50503e36 h1:0MNDFrI0gsXivKHSK1YSLqTkrOzYk5QXZeii04Bx714= -github.com/zarazaex69/j v0.0.0-20260515222039-806b50503e36/go.mod h1:7/ypJTenOIPx23fpo5uF7l4u+rxZqg9cFbTL/N77Ktc= github.com/zarazaex69/j v0.0.0-20260516013155-bffcfe38e7d9 h1:hsD5J10K8xUJ1AOg2A5SLYDSCz/tw7WOOoaiO69KafY= github.com/zarazaex69/j v0.0.0-20260516013155-bffcfe38e7d9/go.mod h1:7/ypJTenOIPx23fpo5uF7l4u+rxZqg9cFbTL/N77Ktc= github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ= diff --git a/internal/app/session/session.go b/internal/app/session/session.go index f901cd6..e9b3226 100644 --- a/internal/app/session/session.go +++ b/internal/app/session/session.go @@ -600,6 +600,7 @@ func isLoopbackListenHost(host string) bool { func Run(ctx context.Context, cfg Config) error { cfg = ApplyTransportDefaults(cfg) cfg = ApplyLivenessDefaults(cfg) + configureDefaultResolver(cfg.DNSServer) roomURL := cfg.RoomID liveness, err := livenessConfig(cfg) if err != nil { @@ -623,6 +624,19 @@ func Run(ctx context.Context, cfg Config) error { return run(ctx) } +func configureDefaultResolver(dnsServer string) { + if dnsServer == "" { + return + } + net.DefaultResolver = &net.Resolver{ + PreferGo: true, + Dial: func(ctx context.Context, network, _ string) (net.Conn, error) { + d := net.Dialer{Timeout: 3 * time.Second} + return d.DialContext(ctx, network, dnsServer) + }, + } +} + func runOnce( ctx context.Context, cfg Config, @@ -775,6 +789,7 @@ func genRetry(ctx context.Context, fn func(context.Context) error) error { // Gen creates cfg.Amount rooms for the configured auth provider and writes each room ID to out. func Gen(ctx context.Context, cfg Config, out func(string)) error { + configureDefaultResolver(cfg.DNSServer) p, err := auth.Get(cfg.Auth) if err != nil { return fmt.Errorf("%w: %s", ErrUnsupportedCarrier, cfg.Auth) @@ -787,7 +802,7 @@ func Gen(ctx context.Context, cfg Config, out func(string)) error { var roomID string err := genRetry(ctx, func(ctx context.Context) error { var genErr error - roomID, genErr = creator.CreateRoom(ctx, auth.Config{Name: names.Generate()}) + roomID, genErr = creator.CreateRoom(ctx, auth.Config{Name: names.Generate(), DNSServer: cfg.DNSServer}) if genErr != nil { return fmt.Errorf("CreateRoom: %w", genErr) } diff --git a/internal/server/server.go b/internal/server/server.go index 338d8fd..5b3589e 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -247,13 +247,13 @@ func (s *Server) bringUpLink( }) logger.Infof("Connecting transport=%s carrier=%s ...", cfg.Transport, cfg.Carrier) + s.installSession() + if err := ln.Connect(ctx); err != nil { return fmt.Errorf("failed to connect link: %w", err) } logger.Infof("Link connected") - s.installSession() - s.wg.Add(1) go func() { defer s.wg.Done() @@ -517,11 +517,11 @@ func (s *Server) Status() control.Status { return s.health.Status() } -func (s *Server) recordSession(sessionID string) { s.health.RecordSession(sessionID) } -func (s *Server) recordPong(h control.Health) { s.health.RecordPong(h) } -func (s *Server) recordMissed(missed int) { s.health.RecordMissed(missed) } -func (s *Server) recordUnhealthy(missed int) { s.health.RecordUnhealthy(missed) } -func (s *Server) recordReconnect() { s.health.RecordReconnect() } +func (s *Server) recordSession(sessionID string) { s.health.RecordSession(sessionID) } +func (s *Server) recordPong(h control.Health) { s.health.RecordPong(h) } +func (s *Server) recordMissed(missed int) { s.health.RecordMissed(missed) } +func (s *Server) recordUnhealthy(missed int) { s.health.RecordUnhealthy(missed) } +func (s *Server) recordReconnect() { s.health.RecordReconnect() } func (s *Server) shutdown() { s.closeSession()