Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reporter should be more aggressive about pruning output #245

Closed
dsnet opened this issue Nov 21, 2020 · 1 comment · Fixed by #248
Closed

Reporter should be more aggressive about pruning output #245

dsnet opened this issue Nov 21, 2020 · 1 comment · Fixed by #248
Labels

Comments

@dsnet
Copy link
Collaborator

dsnet commented Nov 21, 2020

The following snippet hangs:

mx := &descriptorpb.FileDescriptorProto{Name: proto.String("descriptor.proto")}
my := &descriptorpb.FileDescriptorProto{Name: proto.String("descriptor.proto")}

x := map[*descriptorpb.FileDescriptorProto]int{mx: 1}
y := map[*descriptorpb.FileDescriptorProto]int{my: 1}

cmp.Diff(x, y)

These two objects are inequal since map keys use == and not a recursive application of cmp.Equal. It hangs because cmp.Diff is trying to format the raw data structure for a descriptorpb.FileDescriptorProto. Since descriptorpb.FileDescriptorProto has a pointer to the protobuf type information, which itself closes over the transitive set of reachable protobuf types, this is a massive data structure. The reporter logic should be more aggressive about pruning the formatted value.

@dsnet dsnet added the bug label Nov 21, 2020
@dsnet
Copy link
Collaborator Author

dsnet commented Nov 23, 2020

The issue is that formatMapKey does not impose any verbosity limits:

func formatMapKey(v reflect.Value, disambiguate bool, ptrs *pointerReferences) string {
var opts formatOptions
opts.DiffMode = diffIdentical
opts.TypeMode = elideType
opts.PrintAddresses = disambiguate
opts.AvoidStringer = disambiguate
opts.QualifiedNames = disambiguate
s := opts.FormatValue(v, reflect.Map, ptrs).String()
return strings.TrimSpace(s)
}

The fix is to simply impose a sensible verbosity limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant