From 24033de80f55457368fb86fdab68b0a66c367776 Mon Sep 17 00:00:00 2001 From: ThrawnCA Date: Fri, 12 Jan 2024 09:20:59 +1000 Subject: [PATCH] [QOLSVC-3902] reduce lock timeout to avoid deadlocks - When clearing and reloading a resource, shorten the lock timeout so we fail fast instead of deadlocking --- ckanext/xloader/loader.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ckanext/xloader/loader.py b/ckanext/xloader/loader.py index bf56431e..ec7bf249 100644 --- a/ckanext/xloader/loader.py +++ b/ckanext/xloader/loader.py @@ -116,11 +116,9 @@ def _clear_datastore_resource(resource_id): ''' Delete all records from the datastore table, without dropping the table itself. ''' engine = get_write_engine() - connection = engine.connect() - try: - connection.execute('TRUNCATE TABLE "{}"'.format(resource_id)) - finally: - connection.close() + with engine.begin() as conn: + conn.execute("SET LOCAL lock_timeout = '5s'") + conn.execute('TRUNCATE TABLE "{}"'.format(resource_id)) def load_csv(csv_filepath, resource_id, mimetype='text/csv', logger=None):