[Trunk / 7.0] crash when duplicating a database from the web interface

Bug #1180000 reported by Alexandre Fayolle - camptocamp
22
This bug affects 4 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Confirmed
Medium
OpenERP's Framework R&D

Bug Description

I got the following crash when trying to duplicate a database from the web interface:

Client Traceback (most recent call last):
  File "/srv/openerp/instances/openerp_prod/parts/webclient/addons/web/http.py", line 203, in dispatch
    response["result"] = method(self, **self.params)
  File "/srv/openerp/instances/openerp_prod/parts/webclient/addons/web/controllers/main.py", line 733, in duplicate
    return req.session.proxy("db").duplicate_database(*duplicate_attrs)
  File "/srv/openerp/instances/openerp_prod/parts/webclient/addons/web/session.py", line 31, in proxy_method
    result = self.session.send(self.service_name, method, *args)
  File "/srv/openerp/instances/openerp_prod/parts/webclient/addons/web/session.py", line 104, in send
    raise xmlrpclib.Fault(openerp.tools.ustr(e), formatted_info)

Server Traceback (most recent call last):
  File "/srv/openerp/instances/openerp_prod/parts/webclient/addons/web/session.py", line 90, in send
    return openerp.netsvc.dispatch_rpc(service_name, method, args)
  File "/srv/openerp/instances/openerp_prod/parts/server/openerp/netsvc.py", line 293, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/srv/openerp/instances/openerp_prod/parts/server/openerp/service/web_services.py", line 122, in dispatch
    return fn(*params)
  File "/srv/openerp/instances/openerp_prod/parts/server/openerp/service/web_services.py", line 178, in exp_duplicate_database
    cr.execute("""CREATE DATABASE "%s" ENCODING 'unicode' TEMPLATE "%s" """ % (db_name, db_original_name))
  File "/srv/openerp/instances/openerp_prod/parts/server/openerp/sql_db.py", line 161, in wrapper
    return f(self, *args, **kwargs)
  File "/srv/openerp/instances/openerp_prod/parts/server/openerp/sql_db.py", line 226, in execute
    res = self._obj.execute(query, params)
OperationalError: source database "openerp_prod" is being accessed by other users
DETAIL: There are 8 other session(s) using the database.

Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

The instance is running in multi process mode, and it seems that the code in exp_duplicate_database which attempts to disconnect the sessions before lauching the CREATE DATABASE ... TEMPLATE is not multi process aware.

summary: - [7.0] crash when duplicating a database from the web interface
+ [Trunk / 7.0] crash when duplicating a database from the web interface
Changed in openobject-server:
assignee: nobody → OpenERP's Framework R&D (openerp-dev-framework)
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
LIN Yu (lin-yu) wrote :

=== modified file 'server/openerp/service/web_services.py'
--- server/openerp/service/web_services.py 2013-06-30 02:11:42 +0000
+++ server/openerp/service/web_services.py 2013-08-09 08:56:05 +0000
@@ -175,6 +175,18 @@
         cr = db.cursor()
         try:
             cr.autocommit(True) # avoid transaction block
+ def _close_connections(cr):
+ cr.execute('SELECT VERSION()')
+ version = cr.fetchone()[0].split(' ')[1]
+ print version
+ if version > '9.2':
+ cr.execute("""SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '%s'; """%db_original_name)
+ _logger.debug('CLOSE DATABASE CONNECTIONS %s in 9.2', db_original_name)
+ else:
+ cr.execute("""SELECT pg_terminate_backend(pg_stat_activity.procpid) FROM pg_stat_activity WHERE pg_stat_activity.datname = '%s'; """%db_original_name)
+ _logger.debug('CLOSE DATABASE CONNCECTIONS %s in 9.1', db_original_name)
+ return
+ _close_connections(cr)
             cr.execute("""CREATE DATABASE "%s" ENCODING 'unicode' TEMPLATE "%s" """ % (db_name, db_original_name))
         finally:
             cr.close()

Revision history for this message
Mathieu Benoit (mathben) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.