Skip to content

KafkaError.str() raises UnicodeDecodeError #129

Closed
@johnrgregg3

Description

@johnrgregg3

I am running confluent_kafka.version ('0.9.2', 590080), confluent_kafka.libversion ('0.9.3', 590847)
In my on_delivery callback:

def fe_analytics_kafka_cb(err, msg):
if err:
LOG.error("fe_analytics_kafka_cb: error: code %d, name %s",
err.code(), str(err.name()))
fred = err.str()
LOG.error("fe_analytics_kafka_cb: error: code %d, name %s: %s",
err.code(), str(err.name()), str(err.str()))

Note the first LOG message does not have the err.str(), so I can see the code and name. They are:

fe_analytics_kafka_cb: error: code -192, name _MSG_TIMED_OUT

Interestingly, I get hit with the exception merely by calling err.str(), not from trying to log it. That is, the fred = err.str() gets it.

I get this exception:

File "/a/bin/vocfe_app/vocfe.py", line 195, in fe_analytics_kafka_cb
fred = err.str()
UnicodeDecodeError: 'utf8' codec can't decode byte 0xa9 in position 76: invalid start byte

Of course I'd like to be able to see the string, otherwise I only have the name to go on.

I think what is going on is that for _MSG_TIMED_OUT, str() just echos the message that was sent, but the length is off, so random memory beyond the message is attempted to be displayed. I'm sending 76 bytes, and the exceptions are in position 76 or 77, beyond the end of my message. Moreover, sometimes it does not raise the exception, but displays weird stuff after the text of my message (which was a JSON blob):

fe_analytics_kafka_cb: error: code -192, name _MSG_TIMED_OUT: {"test_message": "Fri Feb 17 16:43:53 2017 INITIAL TEST FROM 23.79.234.201"}^Y

See the ^Y at the end? I guess sometimes it gets lucky and the random memory looks like valid unicode, and sometimes it doesn't.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions