What happens if the implementation of IHostedService.StopAsync method does not respond to cancellation requests ? #23742
-
Hi, we are implementing a .NET core 3.1 worker service and we need to register several hosted service to implement the required business. This documentation explains that the StopAsync method of the IHostedService interface should be able to listen to cancellation requests issued after a default 5 seconds timeout. Based on my understanding, the StopAsync method is called by the host during the shutdown process of the host itself. In one of our hosted services we need to call an async method during the hosted service stop process; unfortunately this method does not support cancellation, so there is not a simple way for us to implement the StopAsync method in the proper way. This is our scenario:
What's going to happen at the host level in this scenario ? Is this implementation "dangerous" in any sort ? Is this going to block the host shutdown process in case of a long time needed to complete the execution of The simplest solution to this issue is implementing the class Thanks for helping. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Yes, this could prevent the host from shutting down when requested. I'd rethink how much work you do during shutdown if it's likely to take more than 5 seconds. |
Beta Was this translation helpful? Give feedback.
Yes, this could prevent the host from shutting down when requested. I'd rethink how much work you do during shutdown if it's likely to take more than 5 seconds.