GeezerVison is showing github.com — Segmentation fault when close connection or cursor. · Issue #65 · FirebirdSQL/python3-driver
Segmentation fault when close connection or cursor. #65DescriptionI use python version 3.11.7.
Steps to reproduce:
- Create virtual environment and activate it
python -m venv venv
source venv/bin/activate
- Install firebird-driver:
pip install firebird-driver
- Run the Firebird
5.0.3
sudo systemctl start firebird.service
- Create python file and execute it:
import firebird.driver as fdb
if __name__ == '__main__':
with fdb.connect('localhost:employee', user='SYSDBA', password='masterkey') as conn:
with conn.cursor() as cursor:
with cursor.prepare('SELECT COUNT(*) FROM JOB WHERE 11 < ?') as stmt:
print(cursor.execute(stmt, (12,)).fetchone())
- See output:
(31,)
Ошибка сегментирования (образ памяти сброшен на диск)
Activitypcisar commented on Mar 10, 2026 The problem is that Statement returned by cursor.prepare is freed (via with statement) or with .free() call which in turn crashes the server when connection is closed. When cursor is closed first, the result is direct server crash you observer, however, if it first closes the connection, the story is different. See slightly modified example:
>>> with fdb.connect('localhost:employee', user='SYSDBA', password='masterkey') as conn:
... cursor = conn.cursor()
... with cursor.prepare('SELECT COUNT(*) FROM JOB WHERE 11 < ?') as stmt:
... print(cursor.execute(stmt, (12,)).fetchone())
...
(52,)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/job/python/envs/firebird/lib/python3.11/site-packages/firebird/driver/core.py", line 1805, in __exit__
self.close()
File "/home/job/python/envs/firebird/lib/python3.11/site-packages/firebird/driver/core.py", line 1997, in close
self._close()
File "/home/job/python/envs/firebird/lib/python3.11/site-packages/firebird/driver/core.py", line 1830, in _close
self.main_transaction._finish(DefaultAction.ROLLBACK)
File "/home/job/python/envs/firebird/lib/python3.11/site-packages/firebird/driver/core.py", line 2559, in _finish
self.rollback()
File "/home/job/python/envs/firebird/lib/python3.11/site-packages/firebird/driver/core.py", line 2642, in rollback
self._close_cursors()
File "/home/job/python/envs/firebird/lib/python3.11/site-packages/firebird/driver/core.py", line 2548, in _close_cursors
c.close()
File "/home/job/python/envs/firebird/lib/python3.11/site-packages/firebird/driver/core.py", line 4035, in close
self._clear()
File "/home/job/python/envs/firebird/lib/python3.11/site-packages/firebird/driver/core.py", line 3902, in _clear
self._result.close()
File "/home/job/python/envs/firebird/lib/python3.11/site-packages/firebird/driver/interfaces.py", line 769, in close
self._check()
File "/home/job/python/envs/firebird/lib/python3.11/site-packages/firebird/driver/interfaces.py", line 141, in _check
raise self.__report(DatabaseError, self.status.get_errors())
firebird.driver.types.DatabaseError: operating system directive pthread_mutex_lock failed
-Invalid argument
-Invalid resultset interface
Certainly, freeing the Statement should not crash the server when Connection or Cursor is closed, but I am not sure it's the driver problem. It looks like problem with Firebird 5.0.3 version. Could you confirm the problem with other Firebrid versions (4/3)? I'm kind of busy right now to do it myself. DmEye commented on Mar 16, 2026 ISQL Version: LI-V4.0.6.3221 Firebird 4.0:
The same error:
(52,) Ошибка сегментирования (образ памяти сброшен на диск)
ISQL Version: LI-V3.0.13.33818 Firebird 3.0:
The same error:
(52,) Ошибка сегментирования (образ памяти сброшен на диск)
Perhaps, the problem is the cursor exists but the query result does not?
If I change the code like this, the problem disappears on all versions of Firebird:
import firebird.driver as fdb
if __name__ == '__main__':
with fdb.connect('localhost:employee', user='SYSDBA', password='masterkey') as conn:
with conn.cursor() as cursor:
stmt = cursor.prepare('SELECT COUNT(*) FROM JOB WHERE 11 < ?')
with stmt:
with conn.cursor() as cursor:
print(cursor.execute(stmt, (12,)).fetchone())
DmEye commented on Mar 24, 2026
Certainly, freeing the Statement should not crash the server when Connection or Cursor is closed, but I am not sure it's the driver problem.
The crash occurs in the application, not the DBMS-server. So, I guess it is the driver problem. pcisar commented on Mar 24, 2026 You are wrong, the "crash" happen if Firebird client library, cleanly reported to the driver, see that status vector with error returned by API call is properly converted and raised as DatabaseError. DmEye commented on Mar 25, 2026 Yes, the crash happens thanks to FB client lib. I meant, it does not touch the DBMS server itself.
It is either driver or client lib problem. Perhaps, there is a pointer (python's weakref) to invalid memory in driver somewhere. It also could be an internal client lib memory access error.
If it is a client lib problem, we can just redirect this issue to Firebird, I guess.
So, it is needed to define the root of problem. added a commit that references this issue on Apr 16, 2026This issue will close once commit 447b5fd is merged into the 'master' branch.447b5fd fdcastel commented on Apr 16, 2026 @DmEye could you please verify whether #67 resolves the issue on your end? added a commit that references this issue on Apr 18, 2026This issue will close once commit 642a0e8 is merged into the 'master' branch.642a0e8 DmEye commented on Apr 20, 2026 @fdcastel , Yes, the issue is resolved by #67. Thanks you!
I checked the fix on the next Firebird version:
- 3.0.13.33818
- 4.0.6.3221
- 5.0.3.1683
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|