File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,9 @@ const (
1313 CmdAdd = "ADD"
1414 CmdDel = "DEL"
1515
16+ // CNI errors.
17+ ErrRuntime = 100
18+
1619 // DefaultVersion is the CNI version used when no version is specified in a network config file.
1720 defaultVersion = "0.2.0"
1821)
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ package cni
66import (
77 "fmt"
88 "os"
9+ "runtime"
910
1011 "github.com/Azure/azure-container-networking/common"
1112 "github.com/Azure/azure-container-networking/log"
@@ -85,7 +86,25 @@ func (plugin *Plugin) Uninitialize() {
8586}
8687
8788// Execute executes the CNI command.
88- func (plugin * Plugin ) Execute (api PluginApi ) error {
89+ func (plugin * Plugin ) Execute (api PluginApi ) (err error ) {
90+ // Recover from panics and convert them to CNI errors.
91+ defer func () {
92+ if r := recover (); r != nil {
93+ buf := make ([]byte , 1 << 12 )
94+ len := runtime .Stack (buf , false )
95+
96+ cniErr := & cniTypes.Error {
97+ Code : ErrRuntime ,
98+ Msg : fmt .Sprintf ("%v" , r ),
99+ Details : string (buf [:len ]),
100+ }
101+ cniErr .Print ()
102+ err = cniErr
103+
104+ log .Printf ("[cni] Recovered panic: %v %v\n " , cniErr .Msg , cniErr .Details )
105+ }
106+ }()
107+
89108 // Set supported CNI versions.
90109 pluginInfo := cniVers .PluginSupports (supportedVersions ... )
91110
You can’t perform that action at this time.
0 commit comments