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
GetNextIncludedTimeUtc method is very slow or crashes #2270
Comments
The following calendar configuration crashes on [Test]
public void GetNextIncludedTimeUtc()
{
TimeZoneInfo timeZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
var weeklyCalendar = new WeeklyCalendar()
{
TimeZone = timeZone,
};
var dailyCalendar = new DailyCalendar(weeklyCalendar, "06:00", "22:00")
{
TimeZone = timeZone,
InvertTimeRange = true,
};
var holidayCalendar = new HolidayCalendar(dailyCalendar)
{
TimeZone = timeZone,
};
holidayCalendar.AddExcludedDate(new DateTime(2024, 2, 19));
holidayCalendar.AddExcludedDate(new DateTime(2024, 5, 27));
holidayCalendar.AddExcludedDate(new DateTime(2024, 6, 19));
holidayCalendar.AddExcludedDate(new DateTime(2024, 7, 4));
holidayCalendar.AddExcludedDate(new DateTime(2024, 9, 2));
holidayCalendar.AddExcludedDate(new DateTime(2024, 10, 14));
holidayCalendar.AddExcludedDate(new DateTime(2024, 11, 11));
holidayCalendar.AddExcludedDate(new DateTime(2024, 11, 28));
holidayCalendar.AddExcludedDate(new DateTime(2024, 12, 25));
var time = new DateTime(2024, 2, 5, 10, 6, 0, DateTimeKind.Utc);
var expected = new DateTime(2024, 2, 5, 14, 0, 0, DateTimeKind.Utc);
var d = holidayCalendar.GetNextIncludedTimeUtc(time); // throws System.ArgumentOutOfRangeException : The UTC time represented when the offset is applied must be between year 0 and 10,000. (Parameter 'offset')
d.Should().Be(expected);
} |
Possibly related dotnet/runtime#25075 |
The problem here is that |
…o checking modified DateOnly value with base. Changed logic to compare original value with base Calendars, and Date only value with current validator. Add scenario described in quartznet#2270
…o checking modified DateOnly value with base. Changed logic to compare original value with base Calendars, and Date only value with current validator. Add scenario described in quartznet#2270
…o checking modified DateOnly value with base. Changed logic to compare original value with base Calendars, and Date only value with current validator. Add scenario described in quartznet#2270
…increment more coarse at 1sec (vs 1millisecond) quartznet#2270
@al007 Please check if latest 3.x / master branches in repo resolves your issue. |
No, unfortunately, it does not. The example from the 1st post in this thread works even slower now: 20 seconds for .net8 and 50 seconds for net472. However, it does fix the crash for the 2nd example. |
The example you provided should be in the repo, it executes here in about 43ms. Can you please try running.? dotnet test --filter GetNextIncludedTimeUtc_CrashOriginal2270
|
@jafin , this method has two issues: poor performance and a crash. I reported them together because I thought they were related and re-working the algorithm would fix both. Performance issue happens for the following calendar configuration The crash happens for calendar |
@al007 Perhaps I am missing something I copied the example, ran the below against 3.x branch, completed in ~20ms
[Test]
public void GetNextIncludedTimeUtcFirstIssue()
{
TimeZoneInfo timeZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
var holidayCalendar = new HolidayCalendar()
{
TimeZone = timeZone,
};
holidayCalendar.AddExcludedDate(new DateTime(2024, 2, 19));
holidayCalendar.AddExcludedDate(new DateTime(2024, 5, 27));
holidayCalendar.AddExcludedDate(new DateTime(2024, 6, 19));
holidayCalendar.AddExcludedDate(new DateTime(2024, 7, 4));
holidayCalendar.AddExcludedDate(new DateTime(2024, 9, 2));
holidayCalendar.AddExcludedDate(new DateTime(2024, 10, 14));
holidayCalendar.AddExcludedDate(new DateTime(2024, 11, 11));
holidayCalendar.AddExcludedDate(new DateTime(2024, 11, 28));
holidayCalendar.AddExcludedDate(new DateTime(2024, 12, 25));
var weeklyCalendar = new WeeklyCalendar(holidayCalendar)
{
TimeZone = timeZone,
};
var calendar = new DailyCalendar(weeklyCalendar, "06:00", "22:00")
{
TimeZone = timeZone,
InvertTimeRange = true,
};
var time = new DateTime(2024, 2, 5, 10, 6, 0, DateTimeKind.Utc);
var expected = new DateTime(2024, 2, 5, 14, 0, 0, DateTimeKind.Utc);
var d = calendar.GetNextIncludedTimeUtc(time); // takes 13 seconds to execute!
d.Should().Be(expected);
} |
The
GetNextIncludedTimeUtc
method of ICalendar can be extremely slow in certain conditions. The below example creates a calendar that excludes public holidays, weekends, and nighttime. A call to theGetNextIncludedTimeUtc
method of such a calendar takes more than 13 seconds on my machine.Tested version Quartz 3.8.0 from Nuget as well as the latest version of the
main
branch of this repo.The text was updated successfully, but these errors were encountered: