Database Deadlocks While Listing Remote Refs
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Symptoms
Polling Bitbucket Server repositories for changes on projects often fails with a 500 error. This corresponds to a MS SQL Server database deadlock report in the Bitbucket Server logs:
1
2
3
4
5
6
7
8
9
2013-08-15 23:54:44,053 ERROR [http-bio-80-exec-431] 1434x26560x2 10.1.65.60 "GET /mvc/error500 HTTP/1.1" c.a.s.i.web.ErrorPageController There was an unhandled exception loading [/scm/project/acme.git/info/refs]
com.atlassian.bitbucket.exception.DataStoreException: A database error has occurred.
at com.atlassian.bitbucket.internal.aop.ExceptionRewriteAdvice.afterThrowing(ExceptionRewriteAdvice.java:41) ~[bitbucket-platform-2.6.0.jar:na]
at sun.reflect.GeneratedMethodAccessor638.invoke(Unknown Source) ~[na:na]
[...]
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Transaction (Process ID 100) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transac
tion.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216) ~[sqljdbc-4.0.2206.jar:na]
at com.microsoft.sqlserver.jdbc.SQLServerResultSet$FetchBuffer.nextRow(SQLServerResultSet.java:4853) ~[sqljdbc-4.0.2206.jar:na]
Cause
The snapshot settings have not been applied when creating the database.
Resolution
Stop Bitbucket Server and apply the following settings to your database:
1
2
3
4
5
6
7
8
ALTER DATABASE $(DATABASE) SET ALLOW_SNAPSHOT_ISOLATION ON
GO
ALTER DATABASE $(DATABASE) SET READ_COMMITTED_SNAPSHOT ON
GO
SET NOCOUNT OFF
GO
Setting the READ_COMMITTED_SNAPSHOT
will wait until all active connections to the database are closed. Other active connections will block the query from running and it will appear as if the query is hung.
Was this helpful?