-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
asynchronous method 'Quartz.Core.QuartzSchedulerThread.Run()', is waiting on a synchronous call to method 'System.Threading.Monitor.Wait(object, int)' #2354
Comments
Would you like to submit a PR and propose some improvements? |
Sure! I am looking at it now. |
A9G-Data-Droid
added a commit
to A9G-Data-Droid/quartznet
that referenced
this issue
May 9, 2024
- Avoid blocking synchronously in async methods - Ignore new warnings when WONTFIX deferred - Don't run async methods synchronously if you can avoid it - Convert ValueTask ToTask if you must run synchronously - Implement JoinableTask when awaiting from multiple places quartznet#2354 Possibly related to quartznet#2133
A9G-Data-Droid
added a commit
to A9G-Data-Droid/quartznet
that referenced
this issue
May 9, 2024
- Avoid blocking synchronously in async methods - Ignore new warnings when WONTFIX deferred - Don't run async methods synchronously if you can avoid it - Convert ValueTask ToTask if you must run synchronously - Implement JoinableTask when awaiting from multiple places quartznet#2354 Possibly related to quartznet#2133
This was referenced May 10, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
I have a windows service I wrote in .NET8 that builds Quartz as a hosted service. It works great. It runs things on a schedule. When my service goes to stop it hangs indefinitely, never fully stopping. The final log I see is right before the quartz shutdown line. I have my services
ExecuteAsync
code wrapped in a try...catch withawait _scheduling.Shutdown().ConfigureAwait(false);
in the finally to ensure that this is the last thing it does before returning fromExecuteAsync
where the host would handle the disposing of Quartz and everything else.I attached VS2022 debugger to the hung service, exported a dump, and analyzed it in VS2022.
It says
AA0001 Thread pool thread or asnchronous task blocked on a synchronous call
Potential fix
Version used
Quartz (3.8.1)
To Reproduce
await _scheduling.Shutdown().ConfigureAwait(false);
at the end of yourExecuteAsync
method inside your Windows serviceExpected behavior
.Shutdown
should either complete or throw.Additional context
The debugger help text is fairly clear that there is a problem with the async code pathways. Looking at the code for
Quartz.Core.QuartzSchedulerThread.Run
I do see the usage oflock
andMonitor.Wait(sigLock, timeUntilContinue);
which do not followasync
programming as they are both synchronous. The new way to await a lock in async code is usually SemaphoreSlimThis issue appears to be the reason that AsyncMonitorwas written.
The text was updated successfully, but these errors were encountered: