Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Coredns
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
Coredns
Commits
a0f294e5
Commit
a0f294e5
authored
Apr 11, 2018
by
Ruslan Drozhdzh
Committed by
Miek Gieben
Apr 11, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
plugin/forward: add query timeout (#1665)
parent
ccfe691b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
3 deletions
+62
-3
plugin/forward/forward.go
plugin/forward/forward.go
+14
-1
plugin/forward/health_test.go
plugin/forward/health_test.go
+48
-2
No files found.
plugin/forward/forward.go
View file @
a0f294e5
...
@@ -67,8 +67,19 @@ func (f *Forward) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
...
@@ -67,8 +67,19 @@ func (f *Forward) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
var
span
,
child
ot
.
Span
var
span
,
child
ot
.
Span
var
upstreamErr
error
var
upstreamErr
error
span
=
ot
.
SpanFromContext
(
ctx
)
span
=
ot
.
SpanFromContext
(
ctx
)
i
:=
0
list
:=
f
.
list
()
deadline
:=
time
.
Now
()
.
Add
(
defaultTimeout
)
for
time
.
Now
()
.
Before
(
deadline
)
{
if
i
>=
len
(
list
)
{
// reached the end of list, reset to begin
i
=
0
fails
=
0
}
for
_
,
proxy
:=
range
f
.
list
()
{
proxy
:=
list
[
i
]
i
++
if
proxy
.
Down
(
f
.
maxfails
)
{
if
proxy
.
Down
(
f
.
maxfails
)
{
fails
++
fails
++
if
fails
<
len
(
f
.
proxies
)
{
if
fails
<
len
(
f
.
proxies
)
{
...
@@ -183,3 +194,5 @@ const (
...
@@ -183,3 +194,5 @@ const (
randomPolicy
policy
=
iota
randomPolicy
policy
=
iota
roundRobinPolicy
roundRobinPolicy
)
)
const
defaultTimeout
=
5
*
time
.
Second
plugin/forward/health_test.go
View file @
a0f294e5
...
@@ -45,6 +45,7 @@ func TestHealth(t *testing.T) {
...
@@ -45,6 +45,7 @@ func TestHealth(t *testing.T) {
func
TestHealthTimeout
(
t
*
testing
.
T
)
{
func
TestHealthTimeout
(
t
*
testing
.
T
)
{
const
expected
=
1
const
expected
=
1
i
:=
uint32
(
0
)
i
:=
uint32
(
0
)
q
:=
uint32
(
0
)
s
:=
dnstest
.
NewServer
(
func
(
w
dns
.
ResponseWriter
,
r
*
dns
.
Msg
)
{
s
:=
dnstest
.
NewServer
(
func
(
w
dns
.
ResponseWriter
,
r
*
dns
.
Msg
)
{
if
r
.
Question
[
0
]
.
Name
==
"."
{
if
r
.
Question
[
0
]
.
Name
==
"."
{
// health check, answer
// health check, answer
...
@@ -52,8 +53,15 @@ func TestHealthTimeout(t *testing.T) {
...
@@ -52,8 +53,15 @@ func TestHealthTimeout(t *testing.T) {
ret
:=
new
(
dns
.
Msg
)
ret
:=
new
(
dns
.
Msg
)
ret
.
SetReply
(
r
)
ret
.
SetReply
(
r
)
w
.
WriteMsg
(
ret
)
w
.
WriteMsg
(
ret
)
return
}
}
// not a health check, do a timeout
if
atomic
.
LoadUint32
(
&
q
)
==
0
{
//drop only first query
atomic
.
AddUint32
(
&
q
,
1
)
return
}
ret
:=
new
(
dns
.
Msg
)
ret
.
SetReply
(
r
)
w
.
WriteMsg
(
ret
)
})
})
defer
s
.
Close
()
defer
s
.
Close
()
...
@@ -77,6 +85,7 @@ func TestHealthTimeout(t *testing.T) {
...
@@ -77,6 +85,7 @@ func TestHealthTimeout(t *testing.T) {
func
TestHealthFailTwice
(
t
*
testing
.
T
)
{
func
TestHealthFailTwice
(
t
*
testing
.
T
)
{
const
expected
=
2
const
expected
=
2
i
:=
uint32
(
0
)
i
:=
uint32
(
0
)
q
:=
uint32
(
0
)
s
:=
dnstest
.
NewServer
(
func
(
w
dns
.
ResponseWriter
,
r
*
dns
.
Msg
)
{
s
:=
dnstest
.
NewServer
(
func
(
w
dns
.
ResponseWriter
,
r
*
dns
.
Msg
)
{
if
r
.
Question
[
0
]
.
Name
==
"."
{
if
r
.
Question
[
0
]
.
Name
==
"."
{
atomic
.
AddUint32
(
&
i
,
1
)
atomic
.
AddUint32
(
&
i
,
1
)
...
@@ -88,7 +97,15 @@ func TestHealthFailTwice(t *testing.T) {
...
@@ -88,7 +97,15 @@ func TestHealthFailTwice(t *testing.T) {
ret
:=
new
(
dns
.
Msg
)
ret
:=
new
(
dns
.
Msg
)
ret
.
SetReply
(
r
)
ret
.
SetReply
(
r
)
w
.
WriteMsg
(
ret
)
w
.
WriteMsg
(
ret
)
return
}
if
atomic
.
LoadUint32
(
&
q
)
==
0
{
//drop only first query
atomic
.
AddUint32
(
&
q
,
1
)
return
}
}
ret
:=
new
(
dns
.
Msg
)
ret
.
SetReply
(
r
)
w
.
WriteMsg
(
ret
)
})
})
defer
s
.
Close
()
defer
s
.
Close
()
...
@@ -110,10 +127,39 @@ func TestHealthFailTwice(t *testing.T) {
...
@@ -110,10 +127,39 @@ func TestHealthFailTwice(t *testing.T) {
}
}
func
TestHealthMaxFails
(
t
*
testing
.
T
)
{
func
TestHealthMaxFails
(
t
*
testing
.
T
)
{
s
:=
dnstest
.
NewServer
(
func
(
w
dns
.
ResponseWriter
,
r
*
dns
.
Msg
)
{
// timeout
})
defer
s
.
Close
()
p
:=
NewProxy
(
s
.
Addr
,
nil
/* no TLS */
)
f
:=
New
()
f
.
maxfails
=
2
f
.
SetProxy
(
p
)
defer
f
.
Close
()
req
:=
new
(
dns
.
Msg
)
req
.
SetQuestion
(
"example.org."
,
dns
.
TypeA
)
f
.
ServeDNS
(
context
.
TODO
(),
&
test
.
ResponseWriter
{},
req
)
time
.
Sleep
(
1
*
time
.
Second
)
if
!
p
.
Down
(
f
.
maxfails
)
{
t
.
Errorf
(
"Expected Proxy fails to be greater than %d, got %d"
,
f
.
maxfails
,
p
.
fails
)
}
}
func
TestHealthNoMaxFails
(
t
*
testing
.
T
)
{
const
expected
=
0
const
expected
=
0
i
:=
uint32
(
0
)
i
:=
uint32
(
0
)
s
:=
dnstest
.
NewServer
(
func
(
w
dns
.
ResponseWriter
,
r
*
dns
.
Msg
)
{
s
:=
dnstest
.
NewServer
(
func
(
w
dns
.
ResponseWriter
,
r
*
dns
.
Msg
)
{
// timeout
if
r
.
Question
[
0
]
.
Name
==
"."
{
// health check, answer
atomic
.
AddUint32
(
&
i
,
1
)
ret
:=
new
(
dns
.
Msg
)
ret
.
SetReply
(
r
)
w
.
WriteMsg
(
ret
)
}
})
})
defer
s
.
Close
()
defer
s
.
Close
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment