confluentinc / confluent-kafka-go

Confluent's Apache Kafka Golang client
Apache License 2.0
4.64k stars 658 forks source link

deserializer.Deserialize(topic, data) gives panic: runtime error: invalid memory address or nil pointer dereference #867

Open chayuto opened 2 years ago

chayuto commented 2 years ago

deserializer.Deserialize(topic, data) gives panic: runtime error: invalid memory address or nil pointer dereference

Attempt to deserialise/unmarshall message

How to reproduce

setup code

schemaClient, err := schemaregistry.NewClient(schemaregistry.NewConfig("http://SOMEURL:8083"))
deserializer, err := avro.NewGenericDeserializer(schemaClient, serde.ValueSerde, avro.NewDeserializerConfig()) // not null, no err
fmt.Printf("%s\n", topic) // ok
fmt.Printf("%s\n", string(data)) // ok, this not null

out, err := deserializer.Deserialize(topic, data) // << Throw exception here

console output

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x100b1ebc0]

goroutine 1 [running]:
github.com/confluentinc/confluent-kafka-go/schemaregistry/serde/avro.(*GenericDeserializer).Deserialize(0x140002f8120, {0x1400025a500, 0x10}, {0x14000214230, 0x62, 0x62})
 /Users/chayut/go/pkg/mod/github.com/confluentinc/confluent-kafka-go@v1.9.2/schemaregistry/serde/avro/avro_generic.go:112 +0x100

debug log lines before crash

...
%7|1665015496.741|FETCH|rdkafka#consumer-1| [thrd:XXXbootstrap]:  XXX/1: Fetch topic client_load_avro [3] at offset 0 (v4)
%7|1665015496.742|FETCH|rdkafka#consumer-1| [XXX/bootstrap]: XXX/1: Fetch topic client_load_avro [2] at offset 0 (v4)
%7|1665015496.742|FETCH|rdkafka#consumer-1| [thrd:XXX/bootstrap]: XXX/1: Fetch topic client_load_avro [1] at offset 0 (v4)
%7|1665015496.742|FETCH|rdkafka#consumer-1| [thrd:XXX/bootstrap]: XXX/1: Fetch 4/4/4 toppar(s)
%7|1665015496.742|SEND|rdkafka#consumer-1| [thrd:XXX/bootstrap]: XXX1: Sent FetchRequest (v11, 190 bytes @ 0, CorrId 15)

underlying line that throw the panic github.com/confluentinc/confluent-kafka-go@v1.9.2/schemaregistry/serde/avro/avro_generic.go:112

msg, err := s.MessageFactory(subject, name)

Checklist

Please provide the following information:

chayuto commented 2 years ago
err := deserializer.DeserializeInto(topic, data, &out)

this works ok

gianmarcomennecozzi commented 2 years ago

Same issue for me, deserializer.Deserialize(topic, data) gives panic: runtime error: invalid memory address or nil pointer dereference.

milindl commented 2 years ago

Hello @chayuto , thanks for reporting this.

Are you setting the MessageFactory function on the deserializer, similar to this example?

https://github.com/confluentinc/confluent-kafka-go/blob/50d6a03fc82c08a98891f9e19e02a1ff13ef74cb/schemaregistry/serde/avro/avro_generic_test.go#L105

If it isn't set, it's nil by default and might be giving you this error. The method NewGenericDeserializer by itself doesn't set this method.

If it is not set, could you try once after setting the method?

chayuto commented 1 year ago

@milindl

that's probably not set.

would prefer for lib to give err, rather than panic