-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
Async method that throws Exception not working #124
Comments
Since I wrote this part, and it could potentially affect us, I will look into this. Luckily you can actually evaluate this with any other use-case so that shouldn't block the considering whether you are becoming a patron or not. Note that the Patron stuff is handled by @SimonCropp and I still think you should consider it ;-) |
yes the issue will still be looked at due to this caveat
|
The reason it was not working correctly is because of the throwing of the exception that caused no other exit paths available in the example method. I've much simplified the way MethodTimer deals with async methods by changing the following:
Here is the output of a test console app: The bottom one is from the repro provided by @adrianignat13 Here is the updated generated code after weaving for a state machine: StopMethodTimerStopwatch()
MoveNext() As you can see, there are 2 places where
|
This is now deployed. NuGet may take some time to make it available for download. |
Thanks for the quick turnaround. Really great work. I tested it and now the timer is computed correctly. However, the message is still logged twice. Program.AsyncDelay 1039ms If you use the log to count the number of times a method was called, this issue will skew the results. Also, for my understanding, the method with [Timer] throws two exceptions, whereas the manually instrumented one throws only one. What is happening there? |
In my tests it doesn't do it twice (because of the check for -2 in the state machine). Can you update your repro? |
I've updated my repo. |
Can you try with a custom MethodTimeLogger such as this one (then you can actually put breakpoints, etc):
|
I've updated the repo with the MethodTimeLogger you provieded. I sill get the Time method logged twice. [METHODTIMER] Program.AsyncDelay took '1028' ms |
Interesting, will try in an hour or so. |
I can indeed repro this. Investigating the generated IL. The reason is that after throwing the exception, the method does not return. Will create a separate PR to fix this. |
I think the most realist way to solve this is to check whether the stopwatch is actually running. If not, then the method has already finished and does should not take any time anyway (so re-running the same task would not result in another method time log):
|
This is now deployed. NuGet may take some time to make it available for download. thanks a heap to @GeertvanHorrik |
Tested, it works as expected now. Great work @GeertvanHorrik [METHODTIMER] Program.AsyncDelay took '1043' ms |
You should already be a Patron
I am testing Fody to see if we can use it in our project and if so, we will become a patron. If this means that I cannot raise an issue, please ignore this.
Describe the issue
I have a simple async function that awaits a Task and then throws an exception afterwards. When I wrap this with [Time] there are two things that go weird a) the total time is incorrect (the await time is not taken into account) b) the time is written to the console twice.
Minimal Repro
https://github.com/adrianignat13/MethodTimerSample
From output:
Program.AsyncDelay 12ms
Exception thrown: 'System.Exception' in MethodTimerSample.exe
Program.AsyncDelay 12ms
Expected output (manual weaving)
Program.AsyncDelayWithTimer 00:00:01.0291857ms
Exception thrown: 'System.AggregateException' in mscorlib.dll
The text was updated successfully, but these errors were encountered: