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

Logger in SQLiteAckQueue produces UnicodeDecodeError as it tries to print item as a string (Python 2.7) #96

Closed
sgloutnikov opened this issue Mar 27, 2019 · 1 comment

Comments

@sgloutnikov
Copy link
Contributor

I stumbled upon a UnicodeDecodeError: 'ascii' codec can't decode byte... from the logger with certain values in SQLiteAckQueue + Python 2.7. After some investigation, it turns out that the problem lies with log.warning("Can't find item %s from unack cache", item) in combination with from __future__ import unicode_literals on Python 2.7.

Possible solutions:

  1. Remove from __future__ import unicode_literals
  2. Don't log item at all, but acknowledge the warning.

I am personally more in favor of the second approach as I don't think it is safe to be logging items in this situation. Maybe they contain sensitive information, can be very large, etc.

  • Generally how to trigger the exception:
from __future__ import unicode_literals
import logging
import struct

foo = struct.pack("i", 255)
logging.warn("%s", foo)
  • Example in SQLiteAckQueue:
q = SQLiteAckQueue('testdata', auto_resume=True)
inflight_map = dict()

# Generate some messages.
q.put('test')
q.put(struct.pack("i", 255))
q.put('test2')

# Publish message over network. Store 'in flight' messages
for id in range(3):
    foo = q.get()
    inflight_map[id] = foo

# Some time passes and no acknowledgement. Republish them.
time.sleep(1)
q.resume_unack_tasks()
for id in range(4, 7):
    foo = q.get()
    inflight_map[id] = foo

# Some more time passes, and server confirms original messages. Acknowledge them.
# _unack_cache now does not contain the items, and triggers the log with the printing of item as a string.
time.sleep(1)
for id in range(3):
    bar = inflight_map[id]
    q.ack(bar)
@peter-wangxu
Copy link
Owner

@sgloutnikov Agreed with you that should not log the item. I am going to propose a new PR later this week or do you mind send me the mentioned change?

peter-wangxu added a commit that referenced this issue Apr 2, 2019
Don't log queue item contents. Resolves #96
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants