GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Segmentation fault when close connection or cursor. · Issue #65 · FirebirdSQL/python3-driver

Segmentation fault when close connection or cursor. #65

New issue
Copy link
New issue
Copy link
Closed
#67
Closed
Segmentation fault when close connection or cursor.#65
#67
Copy link

Description

@DmEye
DmEye
opened on Mar 10, 2026
Issue body actions

I use python version 3.11.7.

Steps to reproduce:

  1. Create virtual environment and activate it
    python -m venv venv
    source venv/bin/activate
  2. Install firebird-driver:
    pip install firebird-driver
  3. Run the Firebird 5.0.3
    sudo systemctl start firebird.service
  4. 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())

  1. See output:
(31,)
Ошибка сегментирования (образ памяти сброшен на диск)

Activity

  1. pcisar commented on Mar 10, 2026

    @pcisar
    pcisar
    on Mar 10, 2026
    Contributor
    More actions

    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.

  2. DmEye commented on Mar 16, 2026

    @DmEye
    DmEye
    on Mar 16, 2026
    Author
    More actions

    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())
    
  3. DmEye commented on Mar 24, 2026

    @DmEye
    DmEye
    on Mar 24, 2026
    Author
    More actions

    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.

  4. pcisar commented on Mar 24, 2026

    @pcisar
    pcisar
    on Mar 24, 2026
    Contributor
    More actions

    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.

  5. DmEye commented on Mar 25, 2026

    @DmEye
    DmEye
    on Mar 25, 2026
    Author
    More actions

    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.

  6. fdcastel
    added a commit that references this issue on Apr 16, 2026

    Fix segfault when closing cursor/connection after Statement.free(). Fix

    This issue will close once commit 447b5fd is merged into the 'master' branch.
    447b5fd
  7. fdcastel commented on Apr 16, 2026

    @fdcastel
    fdcastel
    on Apr 16, 2026
    Member
    More actions

    @DmEye could you please verify whether #67 resolves the issue on your end?

  8. fdcastel
    added a commit that references this issue on Apr 18, 2026

    Fix segfault when closing cursor/connection after Statement.free(). Fix

    This issue will close once commit 642a0e8 is merged into the 'master' branch.
    642a0e8
  9. DmEye commented on Apr 20, 2026

    @DmEye
    DmEye
    on Apr 20, 2026
    Author
    More actions

    @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
    Reacted by F.D.Castel
  10. pcisar
    closed this as completedin #67on Apr 20, 2026
  11. pcisar
    added a commit that references this issue on Apr 20, 2026

    Merge pull request #67 from fdcastel/fix-issue-65

    ec6a57b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.