1

According to Salesforce's documentation a transaction can wait for up to 10 seconds before throwing an exception with the code "UNABLE_TO_LOCK_ROW". Yet I get the following scenario:

  1. Transaction A begins on object "CustomObject__c" and locks the Master "Contact" record (The execution time is > 5 seconds).
  2. Transaction B begins on object "CustomObject__c" few milliseconds after transaction A began and waits ~3 seconds for the lock on the same master "Contact" record to be released before throwing a DmlExecutionException with the code "UNABLE_TO_LOCK_ROW".

Why does Transaction B wait for so little time instead of the documented 10 seconds?

Note 1: There was no execution of any operation in the ORG for few minutes before Transaction A.

Note 2: The scenario is executed in a Sandbox.

Edit: Following the previous comments, I confirm that no process was running on the background (Confirmed by a SOQL on AsyncApexJob object.

7
  • no batch jobs or managed package operations running while Transaction B executes?
    – cropredy
    Commented Jun 9, 2022 at 18:52
  • +1 to prev comment, you probably have something else going on. If you are sure it's just two transactions, please edit your question and provide a Minimal, Reproducible Example
    – identigral
    Commented Jun 9, 2022 at 19:23
  • Is that supposed to have an impact? Shouldn't Transaction B wait for the full 10 seconds regardless of what's running on the background?
    – alozzi
    Commented Jun 9, 2022 at 20:28
  • Back in 2013, one of my early answers saw the timeout after 4-5 seconds, but later, I confirmed that it did get "about" ten seconds. I ran the code again with some modification to output the wait time, and I rather consistently got about 9980ms of transaction time before timing out. I would hypothesize that it may be because of too much contention in the database?
    – sfdcfox
    Commented Jun 9, 2022 at 22:36
  • I did a profiling on Transaction B, the execution time is around 5 seconds (3 of which is idle waiting for the lock).
    – alozzi
    Commented Jun 10, 2022 at 11:29

0

You must log in to answer this question.

Browse other questions tagged .