-
-
Notifications
You must be signed in to change notification settings - Fork 137
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
Observe canceled tasks in WithCancellation #121
Conversation
Hi @chkimes, I'll merge this anyways |
I actually had to revert your PR because it was pushing to the wrong branch (master) and not dev. |
Should I re-create a PR targeting dev or have you handled that? The simplest way to re-create the behavior would be to set up a handler for unhandled exceptions to observe the exception on the finalizer thread, set up a task that throws an exception after N seconds, use |
We observed this when calls to improperly configured nameservers were timing out, and our unhandled exception handler was writing this exception message to our logs:
|
I'll add the change to the dev branch with some other things, you don't have to create another PR, thanks ;) And thanks for the explanation. I'm wondering if, in general, it is even a good idea to leave the task "running". I guess if I would await the task itself, after the cancellation hit, would also "solve" that problem? |
I think that by using this method, we're accepting that the task cannot be canceled by any other means (e.g. UdpClient methods) - so I'm not sure there's any option for stopping it from "running" and if there were then it would be better to use that option instead of this method. edit: regarding general cleanliness of .NET, as long as the resources that are referencing this task are cleaned up then it will eventually be garbage collected, so there's nothing wrong with leaving it around in the "running" state if it gets orphaned.
That would solve this particular issue but would introduce a new problem, such as if the task never completes for some reason. |
Yeah I agree with not having to await, or in this case better not to, to not block everything. see #124 I also figured that I can remove the custom action callback and just use a CancellationTokenRegistration insterad. |
Fixed one bug where the wrong cancellation token was passed to the async query impl... Removed the custom cancellation callback to dispose UdpClient for example, can now use the cancellation token + a callback registration. Includes other fix from #121
Cool! That's a lot cleaner - and I'm sure easier for people to understand. It took a while of going back and forth for me to realize what the original code was doing :) |
After timeout,
WithCancellation
throws an exception meaning thereturn await task.ConfigureAwait(false);
line is never invoked. If this task is faulted (likely after it was canceled) then it will not be observed and exceptions will be thrown on the finalizer thread.