Mysterious (harmless) error message from the Python bindings (formerly called Dazl)

Often, but not always, I get the following error message when I communicate with a running ledger. Notwithstanding the error, the communication is successful.

It’s harmless but annoying, can I do anything to prevent it from happening?

This is an example command:

from dazl.ledgerutil import ACS

async with dazl.connect(**ENV) as conn:
  acs = ACS(conn, {'*'})
  await acs.start()
  SNAPSHOT = acs.read().result()
  print(f"SNAPSHOT contains {len(SNAPSHOT)} contracts")

The command is being run from a Colab notebook, so I don’t need asyncio.run to run it.

The error message and the success message at the end:

Future exception was never retrieved
future: <Future finished exception=ConnectionClosedError()>
Traceback (most recent call last):
  File "/Users/gyorgybalazsi/Library/Python/3.9/lib/python/site-packages/grpc/aio/_call.py", line 539, in _send_unary_request
    async def _send_unary_request(self) -> ResponseType:
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/dazl/ledger/grpc/conn_aio.py", line 904, in items
    async for event in self._tx_events(tx_filter_pb, offset, self._offset_range.end):
  File "/usr/local/lib/python3.9/site-packages/dazl/ledger/grpc/conn_aio.py", line 958, in _tx_events
    async for response in response_stream:
  File "/Users/gyorgybalazsi/Library/Python/3.9/lib/python/site-packages/grpc/aio/_call.py", line 315, in _fetch_stream_responses
    message = await self._read()
  File "/Users/gyorgybalazsi/Library/Python/3.9/lib/python/site-packages/grpc/aio/_call.py", line 331, in _read
    await self._preparation
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/dazl/ledgerutil/acs.py", line 197, in _main
    async for state, snapshot in snapshots(self._conn, self._queries):
  File "/usr/local/lib/python3.9/site-packages/dazl/ledgerutil/acs.py", line 255, in snapshots
    async for obj in stream:
  File "/usr/local/lib/python3.9/site-packages/dazl/ledger/grpc/conn_aio.py", line 914, in items
    yield event
  File "/usr/local/lib/python3.9/site-packages/dazl/ledger/errors.py", line 97, in __aexit__
    raise ConnectionClosedError() from exc_val
dazl.ledger.errors.ConnectionClosedError
Future exception was never retrieved
future: <Future finished exception=ConnectionClosedError()>
Traceback (most recent call last):
  File "/Users/gyorgybalazsi/Library/Python/3.9/lib/python/site-packages/grpc/aio/_call.py", line 539, in _send_unary_request
    async def _send_unary_request(self) -> ResponseType:
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/dazl/ledger/grpc/conn_aio.py", line 904, in items
    async for event in self._tx_events(tx_filter_pb, offset, self._offset_range.end):
  File "/usr/local/lib/python3.9/site-packages/dazl/ledger/grpc/conn_aio.py", line 958, in _tx_events
    async for response in response_stream:
  File "/Users/gyorgybalazsi/Library/Python/3.9/lib/python/site-packages/grpc/aio/_call.py", line 315, in _fetch_stream_responses
    message = await self._read()
  File "/Users/gyorgybalazsi/Library/Python/3.9/lib/python/site-packages/grpc/aio/_call.py", line 331, in _read
    await self._preparation
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/dazl/ledgerutil/acs.py", line 197, in _main
    async for state, snapshot in snapshots(self._conn, self._queries):
  File "/usr/local/lib/python3.9/site-packages/dazl/ledgerutil/acs.py", line 255, in snapshots
    async for obj in stream:
  File "/usr/local/lib/python3.9/site-packages/dazl/ledger/grpc/conn_aio.py", line 914, in items
    yield event
  File "/usr/local/lib/python3.9/site-packages/dazl/ledger/errors.py", line 97, in __aexit__
    raise ConnectionClosedError() from exc_val
dazl.ledger.errors.ConnectionClosedError
Future exception was never retrieved
future: <Future finished exception=ConnectionClosedError()>
Traceback (most recent call last):
  File "/Users/gyorgybalazsi/Library/Python/3.9/lib/python/site-packages/grpc/aio/_call.py", line 539, in _send_unary_request
    async def _send_unary_request(self) -> ResponseType:
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/dazl/ledger/grpc/conn_aio.py", line 904, in items
    async for event in self._tx_events(tx_filter_pb, offset, self._offset_range.end):
  File "/usr/local/lib/python3.9/site-packages/dazl/ledger/grpc/conn_aio.py", line 958, in _tx_events
    async for response in response_stream:
  File "/Users/gyorgybalazsi/Library/Python/3.9/lib/python/site-packages/grpc/aio/_call.py", line 315, in _fetch_stream_responses
    message = await self._read()
  File "/Users/gyorgybalazsi/Library/Python/3.9/lib/python/site-packages/grpc/aio/_call.py", line 331, in _read
    await self._preparation
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/dazl/ledgerutil/acs.py", line 197, in _main
    async for state, snapshot in snapshots(self._conn, self._queries):
  File "/usr/local/lib/python3.9/site-packages/dazl/ledgerutil/acs.py", line 255, in snapshots
    async for obj in stream:
  File "/usr/local/lib/python3.9/site-packages/dazl/ledger/grpc/conn_aio.py", line 914, in items
    yield event
  File "/usr/local/lib/python3.9/site-packages/dazl/ledger/errors.py", line 97, in __aexit__
    raise ConnectionClosedError() from exc_val
dazl.ledger.errors.ConnectionClosedError
SNAPSHOT contains 71 contracts

Thanks for reporting; these usually happy when the connection is being closed while it’s still trying to serve a stream:

async def find_first_event():
    async with connect(...) as conn:
        async with conn.query(...) as stream:
            async for ev in stream:
                return ev

In this case, the stream is broken because each context (async with) is closed, and dazl and grpcio aren’t quite smart enough to suppress CancelledError exceptions when in-use streams are open against an underlying channel that is also being closed.

I’ve filed this issue (Scary (but harmless) warnings when transaction streams and connections are closed · Issue #397 · digital-asset/dazl-client · GitHub) to capture the problem as I understand it; please feel free to comment and/or watch on that.

1 Like

Thank you!