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
b03b5de5
Commit
b03b5de5
authored
Jan 25, 2017
by
Daniel Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make HandleError prevent hot-loops
Add an error "handler" that just sleeps for a bit if errors happen more often than 500ms. Manually tested against #39816.
parent
560f5239
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
1 deletion
+31
-1
runtime.go
staging/src/k8s.io/apimachinery/pkg/util/runtime/runtime.go
+31
-1
No files found.
staging/src/k8s.io/apimachinery/pkg/util/runtime/runtime.go
View file @
b03b5de5
...
...
@@ -19,6 +19,8 @@ package runtime
import
(
"fmt"
"runtime"
"sync"
"time"
"github.com/golang/glog"
)
...
...
@@ -79,7 +81,15 @@ func getCallers(r interface{}) string {
// ErrorHandlers is a list of functions which will be invoked when an unreturnable
// error occurs.
var
ErrorHandlers
=
[]
func
(
error
){
logError
}
// TODO(lavalamp): for testability, this and the below HandleError function
// should be packaged up into a testable and reusable object.
var
ErrorHandlers
=
[]
func
(
error
){
logError
,
(
&
rudimentaryErrorBackoff
{
lastErrorTime
:
time
.
Now
(),
minPeriod
:
500
*
time
.
Millisecond
,
})
.
OnError
,
}
// HandlerError is a method to invoke when a non-user facing piece of code cannot
// return an error and needs to indicate it has been ignored. Invoking this method
...
...
@@ -101,6 +111,26 @@ func logError(err error) {
glog
.
ErrorDepth
(
2
,
err
)
}
type
rudimentaryErrorBackoff
struct
{
minPeriod
time
.
Duration
// immutable
// TODO(lavalamp): use the clock for testability. Need to move that
// package for that to be accessible here.
lastErrorTimeLock
sync
.
Mutex
lastErrorTime
time
.
Time
}
// OnError will block if it is called more often than the embedded period time.
// This will prevent overly tight hot error loops.
func
(
r
*
rudimentaryErrorBackoff
)
OnError
(
error
)
{
r
.
lastErrorTimeLock
.
Lock
()
defer
r
.
lastErrorTimeLock
.
Unlock
()
d
:=
time
.
Since
(
r
.
lastErrorTime
)
if
d
<
r
.
minPeriod
{
time
.
Sleep
(
r
.
minPeriod
-
d
)
}
r
.
lastErrorTime
=
time
.
Now
()
}
// GetCaller returns the caller of the function that calls it.
func
GetCaller
()
string
{
var
pc
[
1
]
uintptr
...
...
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