Commit f656c5b2 authored by Jim Fulton's avatar Jim Fulton

Fixed: on lost connections, pending futures weren't completed with ClientDisconected errors.

To make matters worse, when the other site closes a connection, None
is passed to protocol connection_lost methods, which was fouling up
sornstream error detection.
parent c3fb0f5f
from pickle import loads, dumps
from ZEO.Exceptions import ClientDisconnected
from ZODB.ConflictResolution import ResolvedSerial
from struct import unpack
import asyncio
......@@ -78,8 +79,7 @@ class Protocol(asyncio.Protocol):
if self.transport is not None:
self.transport.close()
for future in self.futures.values():
future.set_exception(
ZEO.Exceptions.ClientDisconnected("Closed"))
future.set_exception(ClientDisconnected("Closed"))
self.futures.clear()
def protocol_factory(self):
......@@ -169,7 +169,7 @@ class Protocol(asyncio.Protocol):
logger.info("Disconnected, %s, %r", self, exc)
self.client.disconnected(self)
for f in self.futures.values():
f.set_exception(exc)
f.set_exception(ClientDisconnected(exc or 'connection lost'))
def finish_connect(self, protocol_version):
......@@ -512,7 +512,7 @@ class Client:
self.protocol.call_async(method, args)
future.set_result(None)
else:
future.set_exception(ZEO.Exceptions.ClientDisconnected())
future.set_exception(ClientDisconnected())
def call_async_from_same_thread(self, method, *args):
return self.protocol.call_async(method, args)
......@@ -522,14 +522,13 @@ class Client:
self.protocol.call_async_iter(it)
future.set_result(None)
else:
future.set_exception(ZEO.Exceptions.ClientDisconnected())
future.set_exception(ClientDisconnected())
def _when_ready(self, func, result_future, *args):
if self.ready is None:
# We started without waiting for a connection. (prob tests :( )
result_future.set_exception(
ZEO.Exceptions.ClientDisconnected("never connected"))
result_future.set_exception(ClientDisconnected("never connected"))
else:
@self.connected.add_done_callback
def done(future):
......@@ -726,7 +725,7 @@ class ClientRunner:
# Short circuit from now on. We're closed.
def call_closed(*a, **k):
raise ZEO.Exceptions.ClientDisconnected('closed')
raise ClientDisconnected('closed')
self.__call = call_closed
......
......@@ -226,8 +226,10 @@ class AsyncTests(setupstack.TestCase, ClientRunner):
protocol.connection_lost(exc)
wrapper.notify_disconnected.assert_called_with()
self.assertEqual(loaded.exception(), exc)
self.assertEqual(f1.exception(), exc)
self.assertTrue(isinstance(loaded.exception(), ClientDisconnected))
self.assertEqual(loaded.exception().args, (exc,))
self.assertTrue(isinstance(f1.exception(), ClientDisconnected))
self.assertEqual(f1.exception().args, (exc,))
# Because we reconnected, a new protocol and transport were created:
self.assert_(protocol is not loop.protocol)
......
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