Fix panic in new tcp based dns resolver

Use service worker in order to survive future panics better
This commit is contained in:
Daniel 2020-07-08 16:06:20 +02:00
parent 2afd9cd143
commit 96fcc6993c

View file

@ -102,7 +102,9 @@ connMgmt:
if tr.dnsConnection != nil { if tr.dnsConnection != nil {
connClosing.Set() connClosing.Set()
_ = tr.dnsConnection.Close() _ = tr.dnsConnection.Close()
cancelConnCtx() if cancelConnCtx != nil {
cancelConnCtx()
}
tr.dnsConnection = nil tr.dnsConnection = nil
atomic.AddUint32(tr.connInstanceID, 1) atomic.AddUint32(tr.connInstanceID, 1)
@ -120,9 +122,15 @@ connMgmt:
tr.Unlock() tr.Unlock()
// hint network environment at failed connection // hint network environment at failed connection
netenv.ReportFailedConnection() if failCnt >= FailThreshold {
netenv.ReportFailedConnection()
}
// The linter said so. Don't even...
if cancelConnCtx != nil {
cancelConnCtx()
}
cancelConnCtx() // The linter said so. Don't even...
return nil return nil
} }
@ -209,7 +217,9 @@ connMgmt:
msg, err := conn.ReadMsg() msg, err := conn.ReadMsg()
if err != nil { if err != nil {
if connClosing.SetToIf(false, true) { if connClosing.SetToIf(false, true) {
cancelConnCtx() if cancelConnCtx != nil {
cancelConnCtx()
}
tr.ReportFailure() tr.ReportFailure()
failCnt++ failCnt++
if tr.IsFailing() { if tr.IsFailing() {
@ -249,7 +259,9 @@ connMgmt:
err := tr.dnsConnection.WriteMsg(msg) err := tr.dnsConnection.WriteMsg(msg)
if err != nil { if err != nil {
if connClosing.SetToIf(false, true) { if connClosing.SetToIf(false, true) {
cancelConnCtx() if cancelConnCtx != nil {
cancelConnCtx()
}
tr.ReportFailure() tr.ReportFailure()
failCnt++ failCnt++
if tr.IsFailing() { if tr.IsFailing() {
@ -344,7 +356,7 @@ func (tr *TCPResolver) submitQuery(_ context.Context, q *Query) *InFlightQuery {
// make sure client is started // make sure client is started
if tr.clientStarted.SetToIf(false, true) { if tr.clientStarted.SetToIf(false, true) {
module.StartWorker("dns client", tr.client) module.StartServiceWorker("dns client", 10*time.Millisecond, tr.client)
} }
return inFlight return inFlight