igorcoding / asynctnt

A fast Tarantool Database connector for Python/asyncio.

Home Page:https://igorcoding.github.io/asynctnt

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A problem with reconnect

bofm opened this issue · comments

commented

When a Tarantool instance I am connected to with asynctnt crashes the Connection.connect() method blocks forever despite connect_timeout is set.

# pip install asynctnt

import asynctnt
import asyncio
import logging
from asynctnt.exceptions import TarantoolNotConnectedError

logging.basicConfig()


async def main():
    c = asynctnt.Connection(
        host='localhost',
        port=3301,
        connect_timeout=5,
        request_timeout=5,
        reconnect_timeout=0,
    )
    try:
        while True:
            if not c.is_connected:
                await c.connect()  # <------------- Hangs here after the Tarantool instance crashes
                print('connected')
            try:
                input('press any key to segfalt...')
                await c.eval('''require('ffi').cast('char *', 0)[0] = 48''')
            except TarantoolNotConnectedError as e:
                print('EXCEPTION:', e.__class__.__name__, e)
    finally:
        await c.disconnect()
        print('disconnected')


asyncio.run(main())

Output

$ python t.py
connected
press any key to continue...
EXCEPTION: TarantoolNotConnectedError Lost connection to Tarantool


^Cdisconnected
Traceback (most recent call last):
  File "t.py", line 33, in <module>
    asyncio.run(main())
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 555, in run_until_complete
    self.run_forever()
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 523, in run_forever
    self._run_once()
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 1722, in _run_once
    event_list = self._selector.select(timeout)
  File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/selectors.py", line 558, in select
    kev_list = self._selector.control(None, max_ev, timeout)
KeyboardInterrupt

Python 3.7.0 on MacOS

Fixed in version 0.1.13