问题
(which line of code is being executed in a binary in production, not in Visual Studio)
First a bit of framework for my problem: I have an error that is very difficult to track, because it occurs randomly. In this error, Dapper hangs indefinitely. No timeout exception, no nothing. Just one query that executes indefinitely. Probably a "nasty deadlock case", as Marc Gravell answered in the comments.
In order to narrow down where the problem comes from, 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 my _db.Query
and _db.Execute
(quite a few) with this function. I am not able to track the error when debugging, because it occurs once every 1000(?) executions without a visible pattern. This is why I need to add this wrapper to my code in production, and hope that the additional info that I am catching helps me track down the problem.
Now, it would be much better to know which exact operation is Dapper locked in, hence the title of the question: is there a way to know which line of code is being executed when the timeout occurs? If I could log this info in my exception, this would give me the info about where the deadlock occurs in Dapper.
来源:https://stackoverflow.com/questions/40017402/custom-timeout-is-there-a-way-to-know-which-line-of-code-was-being-executed