My Recent BPT OnReady Re-Surprise

Justin James
2 min readSep 23, 2021

--

Recently while working with a client, we were seeing some unusual behavior. Long story short, they had a button on a screen that was doing some work and then launching a Process that starts with a Human Activity in BPT, then doing a message to the user and redirecting them to another screen. That button was taking 30 seconds to get them to see the message, and the work that was expected to be done by the Human Activity’s OnReady was not getting done for an additional minute. What was happening?

We dug a little deeper into the logs, and we were seeing that a CreateOrUpdate executing in the Human Activity’s OnReady was failing due to a timeout, after 30 seconds on the dot. Well, we know that a CreateOrUpdate can fail due to lock contention within the database, and since this was 100% consistent we know that the contention was occurring due to things happening in the button click.

“But… but… but Justin, doesn’t the BPT execute asynchronously, and even if it starts before the button click finishes, the Process launch would return immediately, allow the button’s logic to finish, commit the transaction, and the OnReady would work fine, why is this happening?” That’s what you are saying right now.

Somewhere in the back of my head, I vaguely remembered a conversation with someone at OutSystems years ago, where I was told that the launch of a Process with an OnStart actually blocks until the OnStart completes! Could it be that an OnReady for a HumanActivity (or another Activity that supports OnReady) might work the same?

Yuuuuuup.

So what is happening here:

  1. The button’s logic does something to lock a record or table up.
  2. The Process is launched and blocks.
  3. The Human Activity is requested to start.
  4. The OnReady is called by the Scheduler Service in a separate thread.
  5. The OnReady tries to make a CreateOrUpdate that fails due to DB contention after 30 seconds.
  6. The OnReady returns with a failure when the CreateOrUpdate fails. It is scheduled to retry a minute later.
  7. The Process launch unblocks and says “I am done!”
  8. The button logic continues and completes and commits its transaction.
  9. The BPT system picks up the OnReady a minute later and retries.
  10. The OnReady of the Activity runs, because the button’s transaction has been committed, it executes with no DB contention issues and successfully completes.

So, what’s the fix? In this case, we had to put a CommitTransaction immediately before the call to launch the Process. I am not always a big fan of CommitTransaction, but sometimes it’s the right approach. Alternatively, we could have taken the work that was being done in the OnReady and do it after the call to launch the Process, in the button’s code.

Bottom line, if you are seeing strange things with DB contention issues or a slow Process launch… look for things occurring in an OnReady of an Activity, or the OnStart of the Process!

J.Ja

--

--