Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
eec1b521
Commit
eec1b521
authored
Aug 29, 2018
by
Dr. Stefan Schimanski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
apiserver: forward panic in WithTimeout filter
parent
9c4cf0a1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
8 deletions
+36
-8
BUILD
staging/src/k8s.io/apiserver/pkg/server/filters/BUILD
+1
-0
timeout.go
staging/src/k8s.io/apiserver/pkg/server/filters/timeout.go
+8
-3
timeout_test.go
...g/src/k8s.io/apiserver/pkg/server/filters/timeout_test.go
+27
-5
No files found.
staging/src/k8s.io/apiserver/pkg/server/filters/BUILD
View file @
eec1b521
...
...
@@ -20,6 +20,7 @@ go_test(
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/diff:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/authentication/user:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/endpoints/filters:go_default_library",
...
...
staging/src/k8s.io/apiserver/pkg/server/filters/timeout.go
View file @
eec1b521
...
...
@@ -91,14 +91,19 @@ func (t *timeoutHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
done
:=
make
(
chan
struct
{})
result
:=
make
(
chan
interface
{})
tw
:=
newTimeoutWriter
(
w
)
go
func
()
{
defer
func
()
{
result
<-
recover
()
}()
t
.
handler
.
ServeHTTP
(
tw
,
r
)
close
(
done
)
}()
select
{
case
<-
done
:
case
err
:=
<-
result
:
if
err
!=
nil
{
panic
(
err
)
}
return
case
<-
after
:
postTimeoutFn
()
...
...
staging/src/k8s.io/apiserver/pkg/server/filters/timeout_test.go
View file @
eec1b521
...
...
@@ -30,6 +30,7 @@ import (
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/runtime"
)
type
recorder
struct
{
...
...
@@ -50,22 +51,33 @@ func (r *recorder) Count() int {
}
func
TestTimeout
(
t
*
testing
.
T
)
{
origReallyCrash
:=
runtime
.
ReallyCrash
runtime
.
ReallyCrash
=
false
defer
func
()
{
runtime
.
ReallyCrash
=
origReallyCrash
}()
sendResponse
:=
make
(
chan
struct
{},
1
)
doPanic
:=
make
(
chan
struct
{},
1
)
writeErrors
:=
make
(
chan
error
,
1
)
timeout
:=
make
(
chan
time
.
Time
,
1
)
resp
:=
"test response"
timeoutErr
:=
apierrors
.
NewServerTimeout
(
schema
.
GroupResource
{
Group
:
"foo"
,
Resource
:
"bar"
},
"get"
,
0
)
record
:=
&
recorder
{}
ts
:=
httptest
.
NewServer
(
WithTimeout
(
http
.
HandlerFunc
(
ts
:=
httptest
.
NewServer
(
With
PanicRecovery
(
With
Timeout
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
<-
sendResponse
_
,
err
:=
w
.
Write
([]
byte
(
resp
))
writeErrors
<-
err
select
{
case
<-
sendResponse
:
_
,
err
:=
w
.
Write
([]
byte
(
resp
))
writeErrors
<-
err
case
<-
doPanic
:
panic
(
"inner handler panics"
)
}
}),
func
(
req
*
http
.
Request
)
(
*
http
.
Request
,
<-
chan
time
.
Time
,
func
(),
*
apierrors
.
StatusError
)
{
return
req
,
timeout
,
record
.
Record
,
timeoutErr
}))
}))
)
defer
ts
.
Close
()
// No timeouts
...
...
@@ -114,4 +126,14 @@ func TestTimeout(t *testing.T) {
if
err
:=
<-
writeErrors
;
err
!=
http
.
ErrHandlerTimeout
{
t
.
Errorf
(
"got Write error of %v; expected %v"
,
err
,
http
.
ErrHandlerTimeout
)
}
// Panics
doPanic
<-
struct
{}{}
res
,
err
=
http
.
Get
(
ts
.
URL
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
res
.
StatusCode
!=
http
.
StatusInternalServerError
{
t
.
Errorf
(
"got res.StatusCode %d; expected %d due to panic"
,
res
.
StatusCode
,
http
.
StatusInternalServerError
)
}
}
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