From 9db126eb65ada4b2233ccb85a0e9c402b7efc5de Mon Sep 17 00:00:00 2001 From: Dean Deng Date: Fri, 15 Jan 2021 14:38:44 -0800 Subject: Combine reference count logs into one message. Otherwise, races can occur between concurrent logs. PiperOrigin-RevId: 352086914 --- pkg/refsvfs2/refs_map.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'pkg') diff --git a/pkg/refsvfs2/refs_map.go b/pkg/refsvfs2/refs_map.go index 9fbc5466f..0472eca3f 100644 --- a/pkg/refsvfs2/refs_map.go +++ b/pkg/refsvfs2/refs_map.go @@ -109,8 +109,7 @@ func LogDecRef(obj CheckedObject, refs int64) { // obj.LogRefs() should be checked before calling logEvent, in order to avoid // calling any text processing needed to evaluate msg. func logEvent(obj CheckedObject, msg string) { - log.Infof("[%s %p] %s:", obj.RefType(), obj, msg) - log.Infof(refs_vfs1.FormatStack(refs_vfs1.RecordStack())) + log.Infof("[%s %p] %s:\n%s", obj.RefType(), obj, msg, refs_vfs1.FormatStack(refs_vfs1.RecordStack())) } // DoLeakCheck iterates through the live object map and logs a message for each @@ -122,10 +121,11 @@ func DoLeakCheck() { defer liveObjectsMu.Unlock() leaked := len(liveObjects) if leaked > 0 { - log.Warningf("Leak checking detected %d leaked objects:", leaked) + msg := fmt.Sprintf("Leak checking detected %d leaked objects:\n", leaked) for obj := range liveObjects { - log.Warningf(obj.LeakMessage()) + msg += obj.LeakMessage() + "\n" } + log.Warningf(msg) } } } -- cgit v1.2.3