Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyPy: commits fail when cursors not closed #694

Open
tilboerner opened this issue Sep 16, 2017 · 1 comment
Open

PyPy: commits fail when cursors not closed #694

tilboerner opened this issue Sep 16, 2017 · 1 comment
Labels

Comments

@tilboerner
Copy link
Collaborator

The underlying problem which lead to #676 is actually not related to Python 2 as @MaxLeiter already noted, but to PyPy. Unfortunately, it's a bug that causes database commits to fail, and probably results in 500 errors to HTTP requests that involve persisting data. PyPy support is broken because of this.

It's caused by a combination of implicitly creating db cursors through connection.execute..., and trusting them to be implicitly closed by garbage collection by the time we want to commit. Unlike CPython, PyPy uses a different garbage collection strategy than refcounting, and does not collect objects right when their last pointer is removed. Therefore, cursors remain open, and sqlite sees their statements as not finalized, which means it will refuse to commit, and possibly also to rollback, with the following error:

OperationalError: cannot commit transaction - SQL statements in progress

You can see this happen in the failing sqlitecache unit tests on travis. I could also reproduce it locally.

I made the tests work by explicitly closing every cursor created in sqlitecache.py. To fix the bug, we need to make sure that db cursors are closed in all code that touches the database.

@tilboerner tilboerner added the bug label Sep 16, 2017
@tilboerner
Copy link
Collaborator Author

Here's the commit that fixes the issue in sqlitecache.py as an example: aa4eea. (The formatting is borked, but in this legacy code that's hardly noticeable. =:0 Ay.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant