Open paulstapleton opened 3 years ago
You could add in the IdentityLinkEntityManagerImpl.deleteTaskIdentityLink
a check if the entity was already deleted and not delete it again.
List<IdentityLinkEntity> removedIdentityLinkEntities = new ArrayList<>(); for (IdentityLinkEntity identityLink : identityLinks) { if (!identityLink.isDeleted()) { delete(identityLink); removedIdentityLinkEntities.add(identityLink); } }
But to me this seems to be a deeper problem with the caching system during the execution in the management service. There is a desynchronization between what is deleted and what is selected. The selection seems to be always from the database for lists.
Describe the bug The
identityLinkCount
field on theTaskEntityImpl
can be incorrectly calculated when an identitylink on the task is deleted multiple times in the same transaction, using the methodtaskService.deleteUserIdentityLink(...)
.Each time the method to delete the identityLink is executed then
identityLinkCount
on the task is reduced by one. If during the same transaction the same identityLink has already been marked for deletion, then theidentityLinkCount
is still reduced by 1 but no extra rows in the database are removed.This can result in a negative
identityLinkCount
and causes issues when the task is completed or deleted. As a negative value for theidentityLinkCount
causes no identityLinks to be removed when the task is removed, and leaves an inconsistency in the database.Note, this only occurs if the deletion occurs in the same transaction and if it is done in a separate transaction then the deletion is a no-op and does not remove 1 from
identityLinkCount
This is an issue for me as I have multiple listeners which manipulate the IdentityLinks on a task. Sometimes these listeners remove the same identityLink during the same transaction and cause this error to occur.
Expected behavior If the same identityLink is deleted multiple times in the same transaction, we should either get an error from the
taskService.deleteUserIdentityLink(...)
or theidentityLinkCount
should not be reduced by 1.Code Here is some code to reproduce the problem in Flowable 6.6.0
The BPMN used is
When running the test there is the following log message and database error. In the log message we can see a negative
IdentityLinkCount
Additional context Seen in Flowable 6.6.0 using H2 and Postgres database.