[Fix] Overlapping duration validation#92
Merged
Abdulsametileri merged 2 commits intomainfrom Dec 15, 2025
Merged
Conversation
4 tasks
Abdulsametileri
approved these changes
Dec 15, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR addresses a critical race condition issue where overlapping
Listen()goroutines could be spawned if the configuredWorkDurationexceeded the calculated cron interval.Problem
Previously, if a user configured a
WorkDurationthat was longer than the interval between cron triggers (e.g., Cron: "Every 1 min", Duration: "2 mins"), thekafka-cronsumerwould start a new listener goroutine while the previous one was still running. This led to:Solution
Instead of throwing a panic (which would be a hard breaking change) or allowing the unsafe behavior, we introduced a Smart Auto-Correction mechanism in the configuration validation phase:
Validate()method checks ifDuration >= CronInterval.DurationtoNonStopWork(0).NonStopWorkmode ensures that the consumer runs continuously in a single goroutine, which is the intended behavior when the duration is set to cover the entire interval (and more).Changes
pkg/kafka/config.go: Added logic to parse the cron expression, calculate the interval, and apply the fix.pkg/kafka/config_test.go: Added unit tests to verify that the auto-correction works as expected and invalid configurations are handled gracefully.Example Scenario
Before:
Consumer: { Cron: "*/1 * * * *", // Every 1 minute Duration: 2 * time.Minute } // Result: Every minute a new goroutine starts. At T+1m, two goroutines run concurrently.After (With this PR):