asyncssh: Future exception was never retrieved - ConnectionLost

I’m trying to handle things correctly so that this error log doesn’t show up under a particular and somewhat contrived scenario. (I tried posting to the user mailing list, twice, but my message was being deleted as soon as I submitted it.)

[ERROR][asyncio][base_events.py:1707] Future exception was never retrieved
future: <Future finished exception=ConnectionLost('Connection lost')

It should be possible to exit cleanly with no error logs in all cases right?

Here’s the program I’ve come up with to reproduce the issue, about 7 or 8 times out of 10, and the log of it’s execution.

import asyncio
import logging
from asyncio import gather, get_event_loop
from time import sleep

import asyncssh
from asyncssh import SSHClient

from redacted.lib.correlate import with_new_correlation_context
from redacted.lib.entrypoint import wrap_entry_point

logger = logging.getLogger(__name__)


class MySSHClient(SSHClient):

    def connection_made(self, conn):
        logger.info('connection_made - blocking sleep for 3 seconds')
        sleep(3)

    def connection_lost(self, exc):
        logger.info('connection_lost')


async def do_work():
    async with asyncssh.connect(
        host='172.20.50.53',
        port=22,
        username='***redacted***',
        password='***redacted***',
        known_hosts=None,
        client_factory=MySSHClient
    ) as c:
        logger.info("Ready to use connection")


@with_new_correlation_context
async def _impl():
    try:
        await asyncio.wait_for(do_work(), timeout=3)
    except asyncio.exceptions.TimeoutError:
        return False
    return True


@wrap_entry_point
async def main():
    get_event_loop().set_debug(True)
    await gather(_impl(), _impl(), return_exceptions=False)


if __name__ == '__main__':
    main()

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 21 (12 by maintainers)

Most upvoted comments

Great - thanks for the confirmation, and for putting together the test code! This change will be included in the next release.