Deadlock while concurrently finishing process instances on MSSQL

Description

Since upgrading from version 5.15 to 5.16, we are getting several deadlocks on the ACT_RU_VARIABLE table when many processes are finished concurrently. The issue seems to arise from the new bulk optimized deletes, which apparently cause MSSQL to escalate the locks.
As a workaround, we have implemented our own version of DbSqlSession in which the optimizeDeleteOperations method just returns its input without changes; we don't get any more deadlocks with this.
I have tried tweaking the indexes to no avail; I am not sure what could be done to avoid the deadlocks in this sort of DELETE; maybe using an IN clause will be different instead of an OR?
This is the stack trace I am getting:


This is the MSSQL deadlock log:

Environment

MSSQL, Windows

Assignee

Joram Barrez

Reporter

Camilo Horovitz

Labels

None

Components

Fix versions

Affects versions

Priority

Major
Configure