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.

alozzi
  • 11
  • 2
  • no batch jobs or managed package operations running while Transaction B executes? – cropredy Jun 09 '22 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 Jun 09 '22 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 Jun 09 '22 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 Jun 09 '22 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 Jun 10 '22 at 11:29
  • EXECUTION_STARTED timestamp is around ~5000000 (5ms) and EXECUTION_FINISHED timestamp is around ~5300000000 (5.3 seconds) so the lock is clearly not maintained for 10 seconds. – alozzi Jun 10 '22 at 13:23
  • @alozzi We don't see your logs and we don't have access to your org. If you believe this is a bug or it's not working as advertised, then open a case with SF support. – identigral Jun 10 '22 at 20:17

0 Answers0