ZeroDivisionError when ci_daily_pipeline_schedule_triggers exceeds 1440
Summary
When Ci::PipelineSchedules::CalculateNextRunService
attempts to parse a natural expression with zero in it, the Gitlab::Ci::CronParser
responds with an error from Fugit
gem: divided by 0 (ZeroDivisionError)
. The zero occurs if the ci_daily_pipeline_schedule_triggers
exceeds 1440.
https://gitlab.com/gitlab-org/gitlab/-/blob/v16.9.0-ee/app/services/ci/pipeline_schedules/calculate_next_run_service.rb#L44-50
irb(main):003:0> daily_limit = 1441
=> 1441
irb(main):004:0> every_x_minutes = (1.day.in_minutes / daily_limit).to_i
=> 0
irb(main):005:0> Gitlab::Ci::CronParser.parse_natural("every #{every_x_minutes} minutes", Time.zone.name)
irb(main):005:0> Gitlab::Ci::CronParser.parse_natural("every #{every_x_minutes} minutes", Time.zone.name)
/opt/gitlab/embedded/lib/ruby/gems/3.1.0/gems/fugit-1.8.1/lib/fugit/cron.rb:561:in `%': divided by 0 (ZeroDivisionError)
Our docs suggest there is no maximum value for this limit: https://gitlab.com/gitlab-org/gitlab/-/blob/76326ae8b898b38c8217ad037ed7122be00e62f0/doc/administration/instance_limits.md#L546
Steps to reproduce
- Create a Pipeline schedule for a project
- Enter Rails Console
- Update the limit as per our docs, but use a number higher than 1440
- Attempt to run the pipeline schedule immediately
Example Project
What is the current bug behavior?
If the limit is set above 1440, scheduled pipelines can't be run
What is the expected correct behavior?
Not allow the limit to exceed 1440
Relevant logs and/or screenshots
Output of checks
Results of GitLab environment info
Expand for output related to GitLab environment info
(For installations with omnibus-gitlab package run and paste the output of: `sudo gitlab-rake gitlab:env:info`) (For installations from source run and paste the output of: `sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)
Results of GitLab application Check
Expand for output related to the GitLab application check
(For installations with omnibus-gitlab package run and paste the output of:
sudo gitlab-rake gitlab:check SANITIZE=true
)(For installations from source run and paste the output of:
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true
)(we will only investigate if the tests are passing)