From 158636229e87a4618ba039bd5ca9bf9eaac89f3d Mon Sep 17 00:00:00 2001 From: Etienne Perot Date: Mon, 22 May 2023 16:19:42 -0700 Subject: [PATCH] Avoid serializing the sharedContext struct in formatting directives. b/283566121 suggests that the `log.Warningf` formatting is introspecting some field that it shouldn't. This adds an explicit `String` function to `sharedContext` to avoid this issue. PiperOrigin-RevId: 534218205 --- pkg/sentry/platform/systrap/shared_context.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/sentry/platform/systrap/shared_context.go b/pkg/sentry/platform/systrap/shared_context.go index b2a8faef2..8c7b419b9 100644 --- a/pkg/sentry/platform/systrap/shared_context.go +++ b/pkg/sentry/platform/systrap/shared_context.go @@ -17,6 +17,7 @@ package systrap import ( "fmt" "runtime" + "strconv" "sync" "sync/atomic" "time" @@ -63,6 +64,11 @@ type sharedContext struct { sleeping bool } +// String returns the ID of this shared context. +func (sc *sharedContext) String() string { + return strconv.Itoa(int(sc.contextID)) +} + const ( // sharedContextReady indicates that a context has new events. sharedContextReady = syncevent.Set(1 << iota) @@ -210,10 +216,10 @@ func (sc *sharedContext) sleepOnState(state sysmsg.ContextState) { panic(fmt.Sprintf("error waiting for state: %v", errno)) } if time.Now().After(deadline) { - log.Warningf("Systrap task goroutine has been waiting on ThreadContext.State futex too long. ThreadContext: %s", sc.shared) + log.Warningf("Systrap task goroutine has been waiting on ThreadContext.State futex too long. ThreadContext: %v", sc) } if sentInterruptOnce { - log.Warningf("The context is still running: %s", sc) + log.Warningf("The context is still running: %v", sc) continue }