mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-08-10 13:20:33 +02:00
all: force re-bootstrapping with timeout error
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
@@ -438,6 +439,11 @@ func (p *prog) proxy(ctx context.Context, req *proxyRequest) *dns.Msg {
|
|||||||
go p.um.checkUpstream(upstreams[n], upstreamConfig)
|
go p.um.checkUpstream(upstreams[n], upstreamConfig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// For timeout error (i.e: context deadline exceed), force re-bootstrapping.
|
||||||
|
var e net.Error
|
||||||
|
if errors.As(err, &e) && e.Timeout() {
|
||||||
|
upstreamConfig.ReBootstrap()
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return answer
|
return answer
|
||||||
|
|||||||
@@ -426,8 +426,9 @@ func (uc *UpstreamConfig) ReBootstrap() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
_, _, _ = uc.g.Do("ReBootstrap", func() (any, error) {
|
_, _, _ = uc.g.Do("ReBootstrap", func() (any, error) {
|
||||||
ProxyLogger.Load().Debug().Msg("re-bootstrapping upstream ip")
|
if uc.rebootstrap.CompareAndSwap(false, true) {
|
||||||
uc.rebootstrap.Store(true)
|
ProxyLogger.Load().Debug().Msg("re-bootstrapping upstream ip")
|
||||||
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user