Skip to content

Commit

Permalink
Robustness: Exit if the plugin is taking too long
Browse files Browse the repository at this point in the history
If the plugin (either networking or IPAM) takes more than 30 seconds
then panic.

Fixes projectcalico/calico#2098
  • Loading branch information
tomdee committed Aug 27, 2018
1 parent 9dca1e4 commit 69569f6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions calico.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,9 @@ func cmdDel(args *skel.CmdArgs) error {
var VERSION string

func main() {
// Panic if the plugin takes too long to run.
utils.StartSelfDestructTimer()

// Set up logging formatting.
logrus.SetFormatter(&logutils.Formatter{})

Expand Down
3 changes: 3 additions & 0 deletions ipam/calico-ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ import (
var VERSION string

func main() {
// Panic if the plugin takes too long to run.
utils.StartSelfDestructTimer()

// Set up logging formatting.
logrus.SetFormatter(&logutils.Formatter{})

Expand Down
11 changes: 11 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"regexp"
"strings"

"time"

"github.com/containernetworking/cni/pkg/skel"
cnitypes "github.com/containernetworking/cni/pkg/types"
"github.com/containernetworking/cni/pkg/types/current"
Expand Down Expand Up @@ -525,3 +527,12 @@ func ParsePools(pools []string, isv4 bool) ([]cnet.IPNet, error) {
}
return result, nil
}

// Causes the current process to exit if it's been running for too long
func StartSelfDestructTimer() {
go func() {
time.Sleep(30 * time.Second)
panic("Execution took too long.")
}()

}

0 comments on commit 69569f6

Please sign in to comment.