ConcurrentModificationError or OperationalError (Deadlock found when trying to get lock; try restarting transaction)

41 views
Skip to first unread message

kgk

unread,
Oct 31, 2012, 8:01:34 PM10/31/12
to turbo...@googlegroups.com

Hello,

  We have a TG 2.1.5 application running against Postgresql and Amazon RDS.    We are often getting a OperationError or a ConcurrentModificationError during some long transactions.   The usual way to deal with them is laid out in [1], which suggests
that the user should simply resubmit transaction due to the transient error.   After looking around repoze.tm2 I note that 
it doesn't look like it will retry.  

1.  Any suggestions for implementing  retries at transaction.manager level.. should we be using the zope.sqlalchemy manager
which does seem to implement some of the retry logic?

It also seems that we could simply ask the client side to reload (return a http 409) and resubmit the entire request. Anybody
have any   experience with this ?

Thanks,
Kris

 



Alessandro Molina

unread,
Oct 31, 2012, 9:42:36 PM10/31/12
to turbo...@googlegroups.com
You should be able to go with:

import transaction
for attempt in transaction.attempts(3):
[...]

It should also be possible to extend it to all your controllers by
using a controller_wrapper.
Simple add to your config/app_cfg.py something like:

def transactions_retry_wrapper(app_config, controller):
def wrapped_controller(*args, **kw):
for attempt in transaction.attempts(3):
return controller(*args, **kw)
return wrapped_controller

base_config.register_hook('controller_wrapper', transactions_retry_wrapper)

Just keep in mind that controller wrappers are a recent addition, I'm
sure they are available on 2.2 and 2.1.5, but I don't remember if they
are on 2.1.4
> --
> You received this message because you are subscribed to the Google Groups
> "TurboGears" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/turbogears/-/5T23ID0fzmgJ.
> To post to this group, send email to turbo...@googlegroups.com.
> To unsubscribe from this group, send email to
> turbogears+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/turbogears?hl=en.

Alessandro Molina

unread,
Oct 31, 2012, 10:07:40 PM10/31/12
to turbo...@googlegroups.com
On Thu, Nov 1, 2012 at 2:42 AM, Alessandro Molina
<alessand...@gmail.com> wrote:
>
> def transactions_retry_wrapper(app_config, controller):
> def wrapped_controller(*args, **kw):
> for attempt in transaction.attempts(3):
> return controller(*args, **kw)
> return wrapped_controller
>
> base_config.register_hook('controller_wrapper', transactions_retry_wrapper)
>

Forgot a with statement here :D
Should have been:

def transactions_retry_wrapper(app_config, controller):
def wrapped_controller(*args, **kw):
for attempt in transaction.attempts(3):
with attempt:
Reply all
Reply to author
Forward
0 new messages