mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-09-17 01:45:27 +02:00
Set deadline for custom UDP/TCP conn
Otherwise, OS resolver may hang forever if the server does not reply. While at it, also removing unused method stopClientInfoDiscover. Updates #344
This commit is contained in:
@@ -581,13 +581,6 @@ func (p *prog) runClientInfoDiscover(ctx context.Context) {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
// stopClientInfoDiscover stops the current client info discover goroutine.
|
|
||||||
// It blocks until the goroutine terminated.
|
|
||||||
func (p *prog) stopClientInfoDiscover() {
|
|
||||||
p.ciTable.Stop()
|
|
||||||
mainLog.Load().Debug().Msg("stopped client info discover")
|
|
||||||
}
|
|
||||||
|
|
||||||
// metricsEnabled reports whether prometheus exporter is enabled/disabled.
|
// metricsEnabled reports whether prometheus exporter is enabled/disabled.
|
||||||
func (p *prog) metricsEnabled() bool {
|
func (p *prog) metricsEnabled() bool {
|
||||||
return p.cfg.Service.MetricsQueryStats || p.cfg.Service.MetricsListener != ""
|
return p.cfg.Service.MetricsQueryStats || p.cfg.Service.MetricsListener != ""
|
||||||
|
|||||||
@@ -289,6 +289,7 @@ func customDNSExchange(ctx context.Context, msg *dns.Msg, server string, desired
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer udpConn.Close()
|
defer udpConn.Close()
|
||||||
|
udpConn.SetDeadline(time.Now().Add(3 * time.Second))
|
||||||
udpDnsConn := &dns.Conn{Conn: udpConn}
|
udpDnsConn := &dns.Conn{Conn: udpConn}
|
||||||
if err = udpDnsConn.WriteMsg(msg); err != nil {
|
if err = udpDnsConn.WriteMsg(msg); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -310,6 +311,7 @@ func customDNSExchange(ctx context.Context, msg *dns.Msg, server string, desired
|
|||||||
return reply, nil // fallback to UDP reply if TCP dial fails.
|
return reply, nil // fallback to UDP reply if TCP dial fails.
|
||||||
}
|
}
|
||||||
defer tcpConn.Close()
|
defer tcpConn.Close()
|
||||||
|
tcpConn.SetDeadline(time.Now().Add(3 * time.Second))
|
||||||
tcpDnsConn := &dns.Conn{Conn: tcpConn}
|
tcpDnsConn := &dns.Conn{Conn: tcpConn}
|
||||||
if err = tcpDnsConn.WriteMsg(msg); err != nil {
|
if err = tcpDnsConn.WriteMsg(msg); err != nil {
|
||||||
return reply, nil // fallback if TCP write fails.
|
return reply, nil // fallback if TCP write fails.
|
||||||
|
|||||||
Reference in New Issue
Block a user