Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent lock timeout thrown by sp_msforeachdb #3180

Merged
merged 4 commits into from
Dec 11, 2022

Conversation

codykonior
Copy link
Contributor

@codykonior codykonior commented Dec 1, 2022

What is the current behavior?

When setting up sp_BlitzFirst in an agent job on a few dozen SQL 2019 with AGs, I was seeing very random periodic job failures caused by lock timeouts. I traced it down to the section where you SET LOCK_TIMEOUT 0 and then look for modified statistics.

You catch the lock timeout error inside the statistics section, but it turns out that sp_msforeachdb is also susceptible to exiting with a lock timeout. By wrapping that in a further try/catch block, I'm able to prevent the job step from failing unnecessarily.

This is nicer than having the job fail randomly, or having to set the job step to exit with success on failure.

If the current behavior is a bug, please provide the steps to reproduce.

I couldn't force the behaviour to happen, even wrapping sp_msforeachdb in a GO 10000 loop and failing over servers everywhere. It's something else. For reference on ~20 servers and running every 15 minutes, one execution would fail every few hours.

What is the expected behavior?
Not throwing that error.

Which versions of SQL Server and which OS are affected by this issue? Did this work in previous versions of our procedures?
SQL 2019 Windows 2016. Unsure if it worked previously.

@codykonior codykonior changed the title Prevent lock failure in sp_msforeachdb Prevent lock timeout thrown by sp_msforeachdb Dec 1, 2022
Copy link
Member

@BrentOzar BrentOzar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pull request! Looks good. Merging into the dev branch, will be in the December release with credit to you in the release notes.

@BrentOzar BrentOzar merged commit b60d8c5 into BrentOzarULTD:dev Dec 11, 2022
@BrentOzar BrentOzar added this to the 2022-12 Release milestone Dec 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants