Publish fails with deadlock

Problem

Publish fails due to publish failing with a deadlock message.

 

Error message in log file looks similar to the below.

Remote publish failed Failed to generate new site Failed to copy database Remove not permitted references Failure to ExecuteNonQueryAsync: delete from [SiteDatabase].[dbo].[ReferenceIdentities] where ReferenceId in (23610577,23610578,23610579,23610580,23610581,23610582,23610583,23610584,23610585,23610586 …);
delete from [SiteDatabase].[dbo].[References] where Id in (23610577,23610578,23610579,23610580,23610581,23610582,23610583,23610584,23610585,23610586 …)
One or more errors occurred.
Transaction (Process ID 52) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.

Solution

The error message is an indication of low resources at publish and reducing the load on the server during publish may resolve the problem. The risk of getting this problem is higher with a small server setup, older versions of Windows Server and SQL versions prior to SQL 2019.

Publishing process runs in multiple processes and default is 5 parallel threads. This is configured in server.config located in C:\ProgramData\Signifikant\Assert

 

<MaxParallelPublisherThread>5</MaxParallelPublisherThread>

 

Reducing max parallel threads may resolve the issue. Time to publish may increase due to this action.