Database Deadlocks While Listing Remote Refs

Troubleshooting Databases

On this page

Still need help?

The Atlassian Community is here for you.

Ask the community

Symptoms

Polling Stash repositories for changes on projects often fails with a 500 error. This corresponds to a MS SQL Server database deadlock report in the Stash logs:

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.stash.exception.DataStoreException: A database error has occurred.
        at com.atlassian.stash.internal.aop.ExceptionRewriteAdvice.afterThrowing(ExceptionRewriteAdvice.java:41) ~[stash-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 Stash and apply the following settings to your database:

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.

Last modified on Mar 30, 2016

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.