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
This commit is contained in:
Etienne Perot
2023-05-22 16:22:27 -07:00
committed by gVisor bot
parent a933719841
commit 158636229e
@@ -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
}