mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Add a panic mode to refs and refsvfs2.
This mode causes a panic rather than just a warning when leaks are detected during a call to DoLeakCheck(). PiperOrigin-RevId: 421885173
This commit is contained in:
committed by
gVisor bot
parent
3cf606d9a4
commit
b5355d8bf9
@@ -238,6 +238,9 @@ const (
|
||||
// LeaksLogTraces indicates that a trace collected during allocation
|
||||
// should be logged when leaks are found.
|
||||
LeaksLogTraces
|
||||
|
||||
// LeaksPanic indidcates that a panic should be issued when leaks are found.
|
||||
LeaksPanic
|
||||
)
|
||||
|
||||
// Set implements flag.Value.
|
||||
@@ -249,6 +252,8 @@ func (l *LeakMode) Set(v string) error {
|
||||
*l = LeaksLogWarning
|
||||
case "log-traces":
|
||||
*l = LeaksLogTraces
|
||||
case "panic":
|
||||
*l = LeaksPanic
|
||||
default:
|
||||
return fmt.Errorf("invalid ref leak mode %q", v)
|
||||
}
|
||||
@@ -271,8 +276,11 @@ func (l LeakMode) String() string {
|
||||
return "log-names"
|
||||
case LeaksLogTraces:
|
||||
return "log-traces"
|
||||
case LeaksPanic:
|
||||
return "panic"
|
||||
default:
|
||||
panic(fmt.Sprintf("invalid ref leak mode %d", l))
|
||||
}
|
||||
panic(fmt.Sprintf("invalid ref leak mode %d", l))
|
||||
}
|
||||
|
||||
// leakMode stores the current mode for the reference leak checker.
|
||||
|
||||
@@ -53,6 +53,12 @@ func leakCheckEnabled() bool {
|
||||
return refs_vfs1.GetLeakMode() != refs_vfs1.NoLeakChecking
|
||||
}
|
||||
|
||||
// leakCheckPanicEnabled returns whether DoLeakCheck() should panic when leaks
|
||||
// are detected.
|
||||
func leakCheckPanicEnabled() bool {
|
||||
return refs_vfs1.GetLeakMode() == refs_vfs1.LeaksPanic
|
||||
}
|
||||
|
||||
// Register adds obj to the live object map.
|
||||
func Register(obj CheckedObject) {
|
||||
if leakCheckEnabled() {
|
||||
@@ -131,6 +137,9 @@ func DoLeakCheck() {
|
||||
for obj := range liveObjects {
|
||||
msg += obj.LeakMessage() + "\n"
|
||||
}
|
||||
if leakCheckPanicEnabled() {
|
||||
panic(msg)
|
||||
}
|
||||
log.Warningf(msg)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user