Commit d03566f0 authored by Jason Madden's avatar Jason Madden

Fix the ruok protocol under Python3: a bytes/unicode problem. However, the...

Fix the ruok protocol under Python3: a bytes/unicode problem. However, the doctest cases still don't pass because they have leading u prefixes in them.
parent 7e2dc318
...@@ -78,7 +78,7 @@ def check(addr, output_metrics, status, per): ...@@ -78,7 +78,7 @@ def check(addr, output_metrics, status, per):
proto = s.recv(struct.unpack(">I", s.recv(4))[0]) proto = s.recv(struct.unpack(">I", s.recv(4))[0])
datas = s.recv(struct.unpack(">I", s.recv(4))[0]) datas = s.recv(struct.unpack(">I", s.recv(4))[0])
s.close() s.close()
data = json.loads(datas) data = json.loads(datas.decode("ascii"))
if not data: if not data:
return warn("No storages") return warn("No storages")
......
...@@ -1332,7 +1332,7 @@ def test_ruok(): ...@@ -1332,7 +1332,7 @@ def test_ruok():
>>> _ = writer.write(struct.pack(">I", 4)+b"ruok") >>> _ = writer.write(struct.pack(">I", 4)+b"ruok")
>>> writer.close() >>> writer.close()
>>> proto = s.recv(struct.unpack(">I", s.recv(4))[0]) >>> proto = s.recv(struct.unpack(">I", s.recv(4))[0])
>>> pprint.pprint(json.loads(s.recv(struct.unpack(">I", s.recv(4))[0]))) >>> pprint.pprint(json.loads(s.recv(struct.unpack(">I", s.recv(4))[0]).decode("ascii")))
{u'1': {u'aborts': 0, {u'1': {u'aborts': 0,
u'active_txns': 0, u'active_txns': 0,
u'commits': 1, u'commits': 1,
......
...@@ -632,8 +632,8 @@ class ManagedServerConnection(Connection): ...@@ -632,8 +632,8 @@ class ManagedServerConnection(Connection):
self.message_output(self.current_protocol) self.message_output(self.current_protocol)
def recv_handshake(self, proto): def recv_handshake(self, proto):
if proto == 'ruok': if proto == b'ruok':
self.message_output(json.dumps(self.mgr.ruok())) self.message_output(json.dumps(self.mgr.ruok()).encode("ascii"))
self.poll() self.poll()
Connection.close(self) Connection.close(self)
else: else:
......
...@@ -271,6 +271,9 @@ class SizedMessageAsyncConnection(asyncore.dispatcher): ...@@ -271,6 +271,9 @@ class SizedMessageAsyncConnection(asyncore.dispatcher):
if isinstance(message, six.binary_type): if isinstance(message, six.binary_type):
size += self.__message_output(messages.pop(0), output) size += self.__message_output(messages.pop(0), output)
elif isinstance(message, six.text_type): elif isinstance(message, six.text_type):
# XXX This can silently lead to data loss and client hangs
# if asserts aren't enabled. Encountered this under Python3
# and 'ruok' protocol
assert False, "Got a unicode message: %s" % repr(message) assert False, "Got a unicode message: %s" % repr(message)
elif message is _close_marker: elif message is _close_marker:
del messages[:] del messages[:]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment