Describe the bug
QuartzHostedService.StopAsync throws NullReferenceException if StartAsync has not been run.
StartAsync won't run if there's another hosted service that is registered earlier and throws in StartAsync. Exception in StartAsync causes Asp.Net Core to begin shutdown during which all hosted services are stopped via StopAsync.
IOW hosted services must not assume in StopAsync that StartAsync has been executed.
Version used
3.2.4
To Reproduce
Expected behavior
QuartzHostedService.StopAsync should check that scheduler is not null.
|
public async Task StartAsync(CancellationToken cancellationToken) |
|
{ |
|
scheduler = await schedulerFactory.GetScheduler(cancellationToken); |
|
await scheduler.Start(cancellationToken); |
|
} |
|
|
|
public Task StopAsync(CancellationToken cancellationToken) |
|
{ |
|
return scheduler.Shutdown(options.Value.WaitForJobsToComplete, cancellationToken); |
|
} |
Describe the bug
QuartzHostedService.StopAsyncthrowsNullReferenceExceptionifStartAsynchas not been run.StartAsyncwon't run if there's another hosted service that is registered earlier and throws inStartAsync. Exception inStartAsynccauses Asp.Net Core to begin shutdown during which all hosted services are stopped viaStopAsync.IOW hosted services must not assume in
StopAsyncthatStartAsynchas been executed.Version used
3.2.4
To Reproduce
Expected behavior
QuartzHostedService.StopAsyncshould check thatscheduleris notnull.quartznet/src/Quartz.Extensions.Hosting/QuartzHostedService.cs
Lines 23 to 32 in 5411524