sqlalchemy-firebird icon indicating copy to clipboard operation
sqlalchemy-firebird copied to clipboard

firebird driver - firebird.driver.types.DatabaseError: connection shutdown

Open Alek5andr opened this issue 1 year ago • 4 comments

Hi!

I coped with the following issue:

Exception ignored in: <function Connection.__del__ at 0x000002CEDE2D5630>
Traceback (most recent call last):
  File "C:\Users\Windows\AppData\Local\Programs\Python\Python310\lib\site-packages\firebird\driver\core.py", line 1662, in __del__
    self._att.detach()
  File "C:\Users\Windows\AppData\Local\Programs\Python\Python310\lib\site-packages\firebird\driver\interfaces.py", line 1181, in detach
    self._check()
  File "C:\Users\Windows\AppData\Local\Programs\Python\Python310\lib\site-packages\firebird\driver\interfaces.py", line 113, in _check
    raise self.__report(DatabaseError, self.status.get_errors())
firebird.driver.types.DatabaseError: connection shutdown

in version 2.1 of sqlalchemy-firebird. However, I've found that the similar issue with "fdb" driver was fixed in https://github.com/pauldex/sqlalchemy-firebird/issues/38. Still it persists with "firebird" driver.

The following code can help to reproduce the error

import json
from sqlalchemy import create_engine
from sqlalchemy.orm import Session
from sqlalchemy import URL
from sqlalchemy import text
from sqlalchemy.orm import sessionmaker


def main():
    fb_cursor = firebird_session()
    fetch_operations_from_fb(fb_cursor)
    fb_cursor.close()


def firebird_session() -> Session:
    with open('../config/database/firebird.json') as f:
        j = json.loads(f.read())

    url_object = URL.create(
        "firebird+firebird",
        username=j["user"],
        password=j["password"],
        host=j["host"],
        port=j["port"],
        database=j["database"],
        query={"charset": "UTF8",
               "fb_client_library": "../clients/firebird3/fbclient.dll"}
    )

    engine = create_engine(url_object, echo=True)
    session = sessionmaker(bind=engine)
    return session()


def fetch_operations_from_fb(session: Session):
    count_query = text('SELECT COUNT(1) FROM USERS;')
    amount_of_users = session.execute(count_query).fetchone()[0]
    print(amount_of_users)


main()

No clue what does cause the error. But 1 thing I've noticed, that making NO query and closing the connection right after its opening does not produce the error.

Any ideas where to dig next or how to overcome the issue are welcomed. Thanks!

P.S. Tools

  • Windows 10
  • Python 3.10
  • Firebird 3
  • SQLAlchemy 2.0.36
  • sqlalchemy-firebird 2.1

Alek5andr avatar Nov 15 '24 10:11 Alek5andr

I'm getting this constantly as well. Similar traceback:

ERROR: Exception during reset or similar
Traceback (most recent call last):
  File "C:\dev\source\lac\.venv\Lib\site-packages\sqlalchemy\pool\base.py", line 986, in _finalize_fairy
    fairy._reset(
  File "C:\dev\source\lac\.venv\Lib\site-packages\sqlalchemy\pool\base.py", line 1432, in _reset
    pool._dialect.do_rollback(self)
  File "C:\dev\source\lac\.venv\Lib\site-packages\sqlalchemy_firebird\firebird.py", line 107, in do_rollback
    dbapi_connection.rollback()
  File "C:\dev\source\lac\.venv\Lib\site-packages\firebird\driver\core.py", line 1926, in rollback
    self.main_transaction.rollback(retaining=retaining, savepoint=savepoint)
  File "C:\dev\source\lac\.venv\Lib\site-packages\firebird\driver\core.py", line 2504, in rollback
    self._tra.rollback()
  File "C:\dev\source\lac\.venv\Lib\site-packages\firebird\driver\interfaces.py", line 438, in rollback
    self._check()
  File "C:\dev\source\lac\.venv\Lib\site-packages\firebird\driver\interfaces.py", line 113, in _check
    raise self.__report(DatabaseError, self.status.get_errors())
firebird.driver.types.DatabaseError: connection shutdown

Similar environment:

  • Windows 11, x64
  • Python 3.13
  • firebird-driver v1.10.9
  • sqlalchemy v2.0.36
  • sqlalchemy-firebird v2.1
  • Firebird 3

Like @Alek5andr, I'm more than happy to provide any additional information to help solve the issue.

CatamountJack avatar Feb 05 '25 05:02 CatamountJack

Sorry for the delay. I have time to work on this now and will reach out when additional info is needed.

pauldex avatar Apr 05 '25 15:04 pauldex

Working on it.

fdcastel avatar Jul 04 '25 06:07 fdcastel

Fixed on #83.

fdcastel avatar Jul 04 '25 06:07 fdcastel