goconvey
goconvey copied to clipboard
Rendering causes endless memory allocations on proto messages
Consider this:
import (
. "github.com/smartystreets/goconvey/convey"
"google.golang.org/protobuf/types/known/wrapperspb"
"log"
"testing"
)
func TestConveyBug(t *testing.T) {
Convey("Given something", t, func() {
var x = &wrapperspb.BoolValue{Value: false}
log.Printf("Receive type %v", x)
So(nil, ShouldResemble, x)
})
}
When I run this test (I actually used GoLand), it starts allocating memory until I kill it.
The problem seems to be in this function (render.go
):
func (s *traverseState) render(buf *bytes.Buffer, ptrs int, v reflect.Value, implicit bool)
Maybe related to #654?
I digged a bit deeper. There are two kind of problems:
- Comparison of proto Messages performed using
ShouldResemble
, which is unreliable. - Rendering of failed comparison for proto Messages, which could hit a cycle.
About the first problem I opened another issue (#664).
Regarding the second problem, the call to Printf
causes x.String()
to be called. This in turn initializes the state
and its atomicMessageInfo
field on the proto message. Therefore, as stated here, via atomicMessageInfo
there may be a problem like a cycle.