Internal server Error when submitting draft invoices

Hello Team

I am currently having issues submitting draft invoices on my instance. When i click on the submit button it says for about 5mins, freezes the enter server and then throws the error message ‘Internal Server Error’

checking the logs is traceback error as below

Traceback (most recent call last):
File “/home/ubuntu/xlevel/apps/erpnext/erpnext/accounts/doctype/sales_invoice/”, line 594, in save_invoice
File “/home/ubuntu/xlevel/apps/frappe/frappe/model/”, line 217, in insert
File “/home/ubuntu/xlevel/apps/frappe/frappe/model/”, line 378, in set_new_name
File “/home/ubuntu/xlevel/apps/frappe/frappe/model/”, line 42, in set_new_name
set_name_from_naming_options(autoname, doc)
File “/home/ubuntu/xlevel/apps/frappe/frappe/model/”, line 71, in set_name_from_naming_options
File “/home/ubuntu/xlevel/apps/frappe/frappe/model/”, line 87, in set_name_by_naming_series = make_autoname(doc.naming_series+’.#####’, ‘’, doc)
File “/home/ubuntu/xlevel/apps/frappe/frappe/model/”, line 116, in make_autoname
n = parse_naming_series(parts, doctype, doc)
File “/home/ubuntu/xlevel/apps/frappe/frappe/model/”, line 131, in parse_naming_series
part = getseries(n, digits, doctype)
File “/home/ubuntu/xlevel/apps/frappe/frappe/model/”, line 159, in getseries
current = frappe.db.sql(“select current from tabSeries where name=%s for update”, (key,))
File “/home/ubuntu/xlevel/apps/frappe/frappe/”, line 199, in sql
self._cursor.execute(query, values)
File “/home/ubuntu/xlevel/env/local/lib/python2.7/site-packages/pymysql/”, line 170, in execute
result = self._query(query)
File “/home/ubuntu/xlevel/env/local/lib/python2.7/site-packages/pymysql/”, line 328, in _query
File “/home/ubuntu/xlevel/env/local/lib/python2.7/site-packages/pymysql/”, line 516, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File “/home/ubuntu/xlevel/env/local/lib/python2.7/site-packages/pymysql/”, line 727, in _read_query_result
File “/home/ubuntu/xlevel/env/local/lib/python2.7/site-packages/pymysql/”, line 1073, in read
File “/home/ubuntu/xlevel/env/local/lib/python2.7/site-packages/pymysql/”, line 1143, in _read_result_packet
File “/home/ubuntu/xlevel/env/local/lib/python2.7/site-packages/pymysql/”, line 1177, in _read_rowdata_packet
packet = self.connection._read_packet()
File “/home/ubuntu/xlevel/env/local/lib/python2.7/site-packages/pymysql/”, line 683, in _read_packet
File “/home/ubuntu/xlevel/env/local/lib/python2.7/site-packages/pymysql/”, line 220, in check_error
File “/home/ubuntu/xlevel/env/local/lib/python2.7/site-packages/pymysql/”, line 109, in raise_mysql_exception
raise errorclass(errno, errval)
InternalError: (1205, u’Lock wait timeout exceeded; try restarting transaction’)

While troubleshooting, i logged on to my database and ran show processlist; which returned image as below

When i kill the running ID with 1316 my server starts responding again…

will appreciate tips to resolve this issue

Perhaps you have an error or some corruption in your naming series table?
Those values are stored in tabSeries.

  • Do you have any custom apps that might have locked this table?
  • Have you run an update/migrate to makes sure the DB schemas are matched?

i have few custom apps but not related to naming series…everything has been running before now, issue just started few weeks back…

i cant run update or migrate on a live server but i did take a backup to a Lab server and i did update and migrate and i still have same issue