Description:
We have implemented a custom RQ job function for payment reconciliation in ERPNext. The job is derived from the trigger_reconciliation_for_queued_docs function in erpnext/accounts/doctype/process_payment_reconciliation/process_payment_reconciliation.py. In our customization, we made minor modifications by commenting out the queue_size code to process all entries at once.
Our goal is to reconcile all customer and supplier payments and invoices in a single run at 2:30 AM daily. While the process handles most of the workload efficiently, we encounter deadlock errors when reconciling high volumes of transactions. This typically occurs for 60–70 transactions, with 4–5 transactions encountering deadlock errors.
Error Details:Error Title: erpnext.accounts.doctype.process_payment_reconciliation.process_payment_reconciliation.fetch_and_allocate
Traceback:
sql
Traceback (most recent call last):
File "apps/frappe/frappe/utils/background_jobs.py", line 220, in execute_job
retval = method(**kwargs)
...
File "apps/frappe/frappe/database/database.py", line 240, in sql
raise frappe.QueryDeadlockError(e) from e
frappe.exceptions.QueryDeadlockError: (1213, 'Deadlock found when trying to get lock; try restarting transaction')
Relevant Context:
We are using 2 workers in a single bench.
The issue arises when the job processes entries in bulk, causing some transactions to fail due to deadlocks.
The affected function is fetch_and_allocate, which leads to deadlocks while performing database operations (INSERT INTO or UPDATE queries) on tabProcess Payment Reconciliation Log Allocations.
Steps to Reproduce:
Implement a custom RQ job similar to trigger_reconciliation_for_queued_docs.
Process all Process Payment Reconciliation Doctype entries in a single run.
Execute the job during high transaction loads.
Observe the deadlock errors in the logs for a subset of transactions.
Information about bug
Description: We have implemented a custom RQ job function for payment reconciliation in ERPNext. The job is derived from the trigger_reconciliation_for_queued_docs function in erpnext/accounts/doctype/process_payment_reconciliation/process_payment_reconciliation.py. In our customization, we made minor modifications by commenting out the queue_size code to process all entries at once. Our goal is to reconcile all customer and supplier payments and invoices in a single run at 2:30 AM daily. While the process handles most of the workload efficiently, we encounter deadlock errors when reconciling high volumes of transactions. This typically occurs for 60–70 transactions, with 4–5 transactions encountering deadlock errors.
Error Details: Error Title: erpnext.accounts.doctype.process_payment_reconciliation.process_payment_reconciliation.fetch_and_allocate Traceback: sql Traceback (most recent call last): File "apps/frappe/frappe/utils/background_jobs.py", line 220, in execute_job retval = method(**kwargs) ... File "apps/frappe/frappe/database/database.py", line 240, in sql raise frappe.QueryDeadlockError(e) from e frappe.exceptions.QueryDeadlockError: (1213, 'Deadlock found when trying to get lock; try restarting transaction')
Relevant Context: We are using 2 workers in a single bench. The issue arises when the job processes entries in bulk, causing some transactions to fail due to deadlocks. The affected function is fetch_and_allocate, which leads to deadlocks while performing database operations (INSERT INTO or UPDATE queries) on tabProcess Payment Reconciliation Log Allocations.
Steps to Reproduce: Implement a custom RQ job similar to trigger_reconciliation_for_queued_docs. Process all Process Payment Reconciliation Doctype entries in a single run. Execute the job during high transaction loads. Observe the deadlock errors in the logs for a subset of transactions.
References: ERPNext Function: trigger_reconciliation_for_queued_docs File Path: erpnext/accounts/doctype/process_payment_reconciliation/process_payment_reconciliation.py
Module
accounts
Version
Environment Details: ERPNext Version: 15.34.0 Frappe Version: 15.39.2 Database: MariaDB Number of Workers: 2 Hosting: Digital Ocean
Installation method
manual install
Relevant log output / Stack trace / Full Error Message.