Custom timeout: is there a way to find out which line of code is being executed?
(which line of code is executing in binary in production and not in Visual Studio)
First, a little frame for my problem: I have an error that is very difficult to track down because it happens randomly. Dapper hangs indefinitely on this error . Eliminate timeout, nothing. Only one request that runs endlessly. Probably an "unpleasant case of deadlock," as Mark Gravell responded in the comments.
To narrow down the problem, I created this timeout function:
/// <summary>
/// Usage:
/// var myResult = GetResultWithTimeout(() => MyFunction());
/// </summary>
public static TResult GetResultWithTimeout<TResult>(Func<TResult> func)
{
var task = Task.Run(func);
if (task.Wait(TimeSpan.FromSeconds(TimeoutInSeconds)))
return task.Result;
else
throw new Exception($"Function timed out: {func.ToString()}");
}
I plan to wrap all mine _db.Query
and _db.Execute
(quite a few) with this function. I can't track the error when debugging because it occurs once every 1000 (?) Executions with no visible pattern. This is why I need to add this wrapper to my code in production, and hopefully the additional information I am catching helps me pinpoint the problem.
Now it would be much better to know exactly which operation is blocked by Dapper, so the title of the question is: Is there a way to find out which line of code is executing when a timeout occurs? If I could write this information to my exception it will give me information about where the deadlock is happening in Dapper.
No one has answered this question yet
See similar questions:
or similar: