module-shipper icon indicating copy to clipboard operation
module-shipper copied to clipboard

Database locking issue - UPDATE shipperhq_quote_item_detail

Open tszmyt-creatuity opened this issue 6 years ago • 3 comments

ShipperHQ: 20.35.1 Magento Version: 2.3.2

Hello there,

I come up with an question about locking issue. Here is a log from production env:

[2020-05-27 15:21:37] report.CRITICAL: Report ID: webapi-5ece8581e3e28; Message: SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction, query was: UPDATE shipperhq_quote_item_detailSETquote_item_id= ?,carrier_group_id= ?,carrier_group= ?,carrier_group_shipping= ? WHERE (id='490970') {"exception":"[object] (Exception(code: 1205): Report ID: webapi-5ece8581e3e28; Message: SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction, query was: UPDATEshipperhq_quote_item_detailSETquote_item_id= ?,carrier_group_id= ?,carrier_group= ?,carrier_group_shipping= ? WHERE (id='490970') at /var/www/html/vendor/magento/framework/Webapi/ErrorProcessor.php:208, Magento\\Framework\\DB\\Adapter\\LockWaitException(code: 1205): SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction, query was: UPDATEshipperhq_quote_item_detailSETquote_item_id= ?,carrier_group_id= ?,carrier_group= ?,carrier_group_shipping= ? WHERE (id='490970') at /var/www/html/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php:589, Zend_Db_Statement_Exception(code: 0): SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction, query was: UPDATEshipperhq_quote_item_detailSETquote_item_id= ?,carrier_group_id= ?,carrier_group= ?,carrier_group_shipping = ? WHERE (id='490970') at /var/www/html/vendor/magento/framework/DB/Statement/Pdo/Mysql.php:110, PDOException(code: HY000): SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction at /var/www/html/vendor/magento/framework/DB/Statement/Pdo/Mysql.php:91)"} []

I tried to debug entire checkout process and invoke this problem on local environment, but no success.

Here is a breakdown of steps in which following update query might be executed:

(I wrote down all places in which ShipperHQ code deals with QuoteItemDetails) a) When being in checkout, following actions regarding quoteItemDetails are executed:

  1. (estimate-shipping-methods endpoint) saveCarrierGroupItem is invoked, quoteItemDetail is created and saved here, shipping methods are displayed to customer, end of request

b) After entering customer data:

  1. (estimate-shipping-methods endpoint) saveCarrierGroupItem is invoked, quoteItemDetails is loaded and updated with selected carrier and saved, end of request

c) When going from Shipping -> Payment in checkout, following actions regarding quoteItemDetails are executed: 1. (shipping-information endpoint) saveCarrierGroupItem is invoked, quoteItemDetails is loaded and updated with selected carrier and saved 2. (same request) just after that, setShippingOnItems is invoked in same request, which tries to load all saved quoteItemDetails and save them instantly (with updated carrier data), end of request

d) After clicking "Place Order":

  1. (place order) saveCarrierGroupItem is invoked, quoteItemDetails is loaded and updated with selected carrier and saved, end of request
  2. (success page load) Second request is being made, which invokes recordOrderItems (which loads quoteItemDetails one-by-one and saves them as orderItemDetails), end of request

I suspect that locking problem happens when going from shipping to payment step in checkout or after placing an order. Saving of quote item details has just finished and then instantly same items are being loaded to be set on quote items (or transformed to order ones).

Could you please take a look at that and maybe come up with an idea why this might be happening?

tszmyt-creatuity avatar Jun 04 '20 11:06 tszmyt-creatuity

Hi @tszmyt Thank you for the detailed description. Judging by your description I would recommend clearing down the quotes table as its contents is not required long-term and/or after the order has been placed. If the quotes table is too large this can cause slow-downs such as this. If this does not resolve please advise, including details of the size of the quotes tables and our developers will investigate further.

wsajason avatar Jun 04 '20 13:06 wsajason

@wsajason Thank you for quick reply, I really appreciate that.

I'll come back here to report how live site behaves after clearing out of outdated quotes (indeed, there are too many of them - I saw that 2.3.5 will fix functionality that should be clearing them by cron).

tszmyt-creatuity avatar Jun 05 '20 06:06 tszmyt-creatuity

Hi @tszmyt As this hasn't been responded to in some time we're closing this call. Let us know if this still occurs.

wsajason avatar Aug 13 '20 16:08 wsajason