Let fatal exceptions when getting locked row count bubble up #971
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Was investigating another issue and noticed that we were getting a number of exceptions like this :
Exception executing query. Message=Unable to acquire exclusive lock on _az_func_Trigger. Result = -999 You attempted to acquire a transactional application lock without an active transaction.
When trying to run the "Acquire leases" command. This shouldn't be possible, since I verified that we always open a transaction at the beginning of each loop iteration. But looking into it I realized that this could happen if an exception occurred during the GetLeaseLockedRowCount command. During that we ignore exceptions that occur (since it's just for debuggability) and so if we got in a situation where the exception was fatal it would cause issues like this.
The fix for this was twofold - first was to let the exceptions bubble up. But the current fatal logic wouldn't handle the specific issue I was seeing with the deadlock, since that isn't fatal for the connection (it's still open and usable). What it does do though is end the transaction - which means that all other queries will fail since a transaction is required for the app lock statement.
So I'm fixing it to let the exception bubble up so at least we don't get the noisy extra errors. This doesn't solve the deadlock problem at all - that's the thing I'm still currently investigating.