Skip to content

Commit

Permalink
Set ConnectionError on pending requests when connection is lost
Browse files Browse the repository at this point in the history
Bump library to 0.5.6
  • Loading branch information
Neil Booth committed Jun 4, 2018
1 parent a60ec89 commit 8da4ef6
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion aiorpcx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .session import *
from .util import *

_version = (0, 5, 5)
_version = (0, 5, 6)
_version_str = '.'.join(str(part) for part in _version)

__all__ = (framing.__all__ +
Expand Down
8 changes: 6 additions & 2 deletions aiorpcx/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


__all__ = ('ClientSession', 'ServerSession', 'Server')
__all__ = ('ClientSession', 'ServerSession', 'Server', 'ConnectionError')


import asyncio
Expand All @@ -39,6 +39,10 @@
from .util import TaskSet, Concurrency


class ConnectionError(RuntimeError):
pass


class SessionBase(asyncio.Protocol, RPCHelperBase):

concurrency_recalc_interval = 15
Expand Down Expand Up @@ -218,7 +222,7 @@ def connection_lost(self, exc):
self.transport = None
self.tasks.cancel_all()
for request in self.all_requests():
request.cancel()
request.set_exception(ConnectionError('connection lost before request completed'))

# App layer
async def wait_closed(self):
Expand Down
9 changes: 9 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ChangeLog
=========

Version 0.5.6
-------------

* Define a ConnectionError exception, and set it on uncomplete
requests when a connection is lost. Previously, those requests were
cancelled, which does not give an informative error message.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Documentation

.. toctree::

changelog
framing
json-rpc
rpc
Expand Down
9 changes: 9 additions & 0 deletions docs/session.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
.. currentmodule:: aiorpcx

Exceptions
----------

.. exception:: ConnectionError

When a connection is lost that has pending requests, this exception is set on
those requests.


Server
======

Expand Down
3 changes: 2 additions & 1 deletion tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ async def test_request_cancelled_on_close(self, server):
async with ClientSession('localhost', server.port) as client:
request = client.send_request('ping', [23])
await asyncio.sleep(0) # Yield to event loop for processing
assert request.cancelled()
with pytest.raises(ConnectionError):
request.result()

@pytest.mark.asyncio
async def test_logging(self, server):
Expand Down

0 comments on commit 8da4ef6

Please sign in to comment.