Panic during proto Marshal

636 views
Skip to first unread message

Mayank Jha

unread,
Jun 19, 2019, 2:02:09 AM6/19/19
to golang-nuts
I am getting the runtime error: invalid memory address or nil pointer dereference, with the following stack trace, but only occasionally when I try to proto.Marshal() a proto message. 

[{"file":"/go/src/github.com/carousell/Cats/Cats/analytics/analytics.go","line":92,"function":"(*producer).Produce.func1"},{"file":"/usr/local/go/src/runtime/asm_amd64.s","line":573,"function":"call32"},{"file":"/usr/local/go/src/runtime/panic.go","line":502,"function":"gopanic"},{"file":"/usr/local/go/src/runtime/panic.go","line":63,"function":"panicmem"},{"file":"/usr/local/go/src/runtime/signal_unix.go","line":388,"function":"sigpanic"},{"file":"/usr/local/go/src/unicode/utf8/utf8.go","line":483,"function":"ValidString"},{"file":"/go/src/github.com/carousell/Cats/vendor/github.com/golang/protobuf/proto/table_marshal.go","line":2074,"function":"appendUTF8StringValueNoZero"},{"file":"/go/src/github.com/carousell/Cats/vendor/github.com/golang/protobuf/proto/table_marshal.go","line":270,"function":"(*marshalInfo).marshal"},{"file":"/go/src/github.com/carousell/Cats/vendor/github.com/golang/protobuf/proto/table_marshal.go","line":2264,"function":"makeMessageSliceMarshaler.func2"},{"file":"/go/src/github.com/carousell/Cats/vendor/github.com/golang/protobuf/proto/table_marshal.go","line":270,"function":"(*marshalInfo).marshal"{"file":"/go/src/github.com/carousell/Cats/vendor/github.com/golang/protobuf/proto/table_marshal.go","line":2234,"function":"makeMessageMarshaler.func2"},{"file":"/go/src/github.com/carousell/Cats/vendor/github.com/golang/protobuf/proto/table_marshal.go","line":270,"function":"(*marshalInfo).marshal"},{"file":"/go/src/github.com/carousell/Cats/vendor/github.com/golang/protobuf/proto/table_marshal.go","line":141,"function":"(*InternalMessageInfo).Marshal"},{"file":"/go/src/github.com/carousell/Cats/Cats/Cats_proto/analytics.pb.go","line":447,"function":"(*AdRequestMsg).XXX_Marshal"},{"file":"/go/src/github.com/carousell/Cats/vendor/github.com/golang/protobuf/proto/table_marshal.go","line":2715,"function":"Marshal"}]


 Have omitted the initial part of the stack trace. Can someone tell me when all could this happen ? Could it be because of a difference in protobuf library versions ? I am unable to get the message, as when the panic happens when the serialization is taking place. Any ideas on how to approach this kind of problem ?

Agniva De Sarker

unread,
Jun 19, 2019, 10:50:18 AM6/19/19
to golang-nuts
This happens when you are trying to access a nil pointer. Check from where the stack trace originates, go to that line and add a "!= nil" check. I guess that is what's happening.

P.S. Your stack trace is in a json format which is for machines to read, not humans. While reporting issues, it helps a lot you present your data (logs, stack trace, etc) in the most clearest way possible.

qiu...@gmail.com

unread,
Jun 19, 2020, 6:57:46 PM6/19/20
to golang-nuts
Hi Mayank, did you find out why this was happening? I'm seeing the exact same backtrace.
Reply all
Reply to author
Forward
0 new messages