Edgewall Software
Modify

Opened 10 years ago

Closed 10 years ago

Last modified 9 years ago

#9104 closed defect (fixed)

reuse of a closed cursor

Reported by: Christian Boos Owned by: Christian Boos
Priority: normal Milestone: 0.11.7
Component: web frontend Version: 0.11-stable
Severity: normal Keywords: pysqlite
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

At least with PySqlite, it's not possible to reuse a cursor after a rollback has been performed on the connection it was created from.

2010-01-08 04:57:04,395 Trac[main] ERROR: Internal Server Error:
Traceback (most recent call last):
  File "/usr/local/virtualenv-0.11/lib/python2.5/site-packages/Trac-0.11.7stable_r8997-py2.5.egg/trac/web/main.py", line 450, in _dispatch_request
    dispatcher.dispatch(req)
  File "/usr/local/virtualenv-0.11/lib/python2.5/site-packages/Trac-0.11.7stable_r8997-py2.5.egg/trac/web/main.py", line 229, in dispatch
    req.session.save()
  File "/usr/local/virtualenv-0.11/lib/python2.5/site-packages/Trac-0.11.7stable_r8997-py2.5.egg/trac/web/session.py", line 100, in save
    (self.sid,))
  File "/usr/local/virtualenv-0.11/lib/python2.5/site-packages/Trac-0.11.7stable_r8997-py2.5.egg/trac/db/util.py", line 64, in execute
    return self.cursor.execute(sql_escape_percent(sql), args)
  File "/usr/local/virtualenv-0.11/lib/python2.5/site-packages/Trac-0.11.7stable_r8997-py2.5.egg/trac/db/sqlite_backend.py", line 80, in execute
    result = PyFormatCursor.execute(self, *args)
  File "/usr/local/virtualenv-0.11/lib/python2.5/site-packages/Trac-0.11.7stable_r8997-py2.5.egg/trac/db/sqlite_backend.py", line 59, in execute
    args or [])
  File "/usr/local/virtualenv-0.11/lib/python2.5/site-packages/Trac-0.11.7stable_r8997-py2.5.egg/trac/db/sqlite_backend.py", line 51, in _rollback_on_error
    return function(self, *args, **kwargs)
ProgrammingError: Cannot operate on a closed cursor.

0.12 version of the same error:

2010-03-02 11:10:25,782 Trac[main] ERROR: Internal Server Error:
Traceback (most recent call last):
  File "build/bdist.linux-x86_64/egg/trac/web/main.py", line 499, in _dispatch_request
    dispatcher.dispatch(req)
  File "build/bdist.linux-x86_64/egg/trac/web/main.py", line 255, in dispatch
    req.session.save()
  File "build/bdist.linux-x86_64/egg/trac/web/session.py", line 88, in save
    @with_transaction(self.env)
  File "build/bdist.linux-x86_64/egg/trac/db/util.py", line 36, in transaction_wrapper
    fn(dbtmp)
  File "build/bdist.linux-x86_64/egg/trac/web/session.py", line 108, in delete_session_cookie
    (self.sid,))
  File "build/bdist.linux-x86_64/egg/trac/db/util.py", line 90, in execute
    return self.cursor.execute(sql_escape_percent(sql), args)
  File "build/bdist.linux-x86_64/egg/trac/db/sqlite_backend.py", line 77, in execute
    result = PyFormatCursor.execute(self, *args)
  File "build/bdist.linux-x86_64/egg/trac/db/sqlite_backend.py", line 56, in execute
    args or [])
  File "build/bdist.linux-x86_64/egg/trac/db/sqlite_backend.py", line 48, in _rollback_on_error
    return function(self, *args, **kwargs)
ProgrammingError: Cannot operate on a closed cursor.

As discussed in ticket:9077#comment:4 point 2.

Attachments (2)

t9104-fix-operate-closed-cursor-r9282.diff (1.9 KB ) - added by Christian Boos 10 years ago.
web: avoid using a cursor after the connection from which it depends has been rollbacked
t9104-fix-operate-closed-cursor-r9282.2.diff (2.0 KB ) - added by Christian Boos 10 years ago.
alternative solution, returning earlier

Download all attachments as: .zip

Change History (8)

by Christian Boos, 10 years ago

web: avoid using a cursor after the connection from which it depends has been rollbacked

comment:1 by Christian Boos, 10 years ago

Please test and review the above patch.

For some background on the problem, see also ticket:9077#comment:10.

comment:2 by Christian Boos, 10 years ago

Or alternatively, we could just return when a concurrent save was detected (#3563), see t9104-fix-operate-closed-cursor-r9282.2.diff.

by Christian Boos, 10 years ago

alternative solution, returning earlier

comment:3 by Christian Boos, 10 years ago

Resolution: fixed
Status: newclosed

First alternative picked for 0.11-stable in r9336, on trunk I'll do the second one.

comment:4 by Christian Boos, 10 years ago

Ported to trunk in r9342, using the second alternative.

comment:5 by anonymous, 9 years ago

Looks like the changes that closed #7663 were removed in the changes that fixed this ticket. I noticed this because I now have .12.1 and am getting the "IntegrityError: duplicate key violates unique constraint "session_attribute_pk"" logged in #7663 during Performance Testing. It actually causes the performance testing to stop due to the high volume of errors (repeating the one below). There are plans to log a defect.

Traceback (most recent call last):

File "build/bdist.linux-x86_64/egg/trac/web/main.py", line 511, in _dispatch_request File "build/bdist.linux-x86_64/egg/trac/web/main.py", line 260, in dispatch File "build/bdist.linux-x86_64/egg/trac/web/session.py", line 88, in save File "build/bdist.linux-x86_64/egg/trac/db/api.py", line 77, in transaction_wrapper File "build/bdist.linux-x86_64/egg/trac/web/session.py", line 113, in delete_session_cookie File "build/bdist.linux-x86_64/egg/trac/db/util.py", line 85, in executemany

IntegrityError: duplicate key value violates unique constraint "session_attribute_pk" IntegrityError: duplicate key value violates unique constraint "session_attribute_pk"

comment:6 by Remy Blank, 9 years ago

The fix has been re-introduced in [10823].

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christian Boos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Christian Boos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.