plugin/forward: make Yield not block (#3336)
* plugin/forward: may Yield not block Yield may block when we're super busy with creating (and looking) for connection. Set a small timeout on Yield, to skip putting the connection back in the queue. Use persistentConn troughout the socket handling code to be more consistent. Signed-off-by: Miek Gieben <miek@miek.nl> Dont do Signed-off-by: Miek Gieben <miek@miek.nl> * Set used in Yield This gives one central place where we update used in the persistConns Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
parent
7b69dfebb5
commit
2d98d520b5
8 changed files with 53 additions and 105 deletions
|
@ -82,54 +82,6 @@ func TestCleanupByTimer(t *testing.T) {
|
|||
tr.Yield(c4)
|
||||
}
|
||||
|
||||
func TestPartialCleanup(t *testing.T) {
|
||||
s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {
|
||||
ret := new(dns.Msg)
|
||||
ret.SetReply(r)
|
||||
w.WriteMsg(ret)
|
||||
})
|
||||
defer s.Close()
|
||||
|
||||
tr := newTransport(s.Addr)
|
||||
tr.SetExpire(100 * time.Millisecond)
|
||||
tr.Start()
|
||||
defer tr.Stop()
|
||||
|
||||
c1, _, _ := tr.Dial("udp")
|
||||
c2, _, _ := tr.Dial("udp")
|
||||
c3, _, _ := tr.Dial("udp")
|
||||
c4, _, _ := tr.Dial("udp")
|
||||
c5, _, _ := tr.Dial("udp")
|
||||
|
||||
tr.Yield(c1)
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
tr.Yield(c2)
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
tr.Yield(c3)
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
tr.Yield(c4)
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
tr.Yield(c5)
|
||||
time.Sleep(40 * time.Millisecond)
|
||||
|
||||
c6, _, _ := tr.Dial("udp")
|
||||
if c6 != c5 {
|
||||
t.Errorf("Expected c6 == c5")
|
||||
}
|
||||
c7, _, _ := tr.Dial("udp")
|
||||
if c7 != c4 {
|
||||
t.Errorf("Expected c7 == c4")
|
||||
}
|
||||
c8, cached, _ := tr.Dial("udp")
|
||||
if cached {
|
||||
t.Error("Expected non-cached connection (c8)")
|
||||
}
|
||||
|
||||
tr.Yield(c6)
|
||||
tr.Yield(c7)
|
||||
tr.Yield(c8)
|
||||
}
|
||||
|
||||
func TestCleanupAll(t *testing.T) {
|
||||
s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {
|
||||
ret := new(dns.Msg)
|
||||
|
@ -150,12 +102,12 @@ func TestCleanupAll(t *testing.T) {
|
|||
{c3, time.Now()},
|
||||
}
|
||||
|
||||
if tr.len() != 3 {
|
||||
if len(tr.conns["udp"]) != 3 {
|
||||
t.Error("Expected 3 connections")
|
||||
}
|
||||
tr.cleanup(true)
|
||||
|
||||
if tr.len() > 0 {
|
||||
if len(tr.conns["udp"]) > 0 {
|
||||
t.Error("Expected no cached connections")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue