Skip to content

Sliding window rate limit not enforced correctly in NextSubscribers( ) #2816

@kumar3202

Description

@kumar3202

Description

When configuring the campaign with all sliding window settings set to 1, including SlidingWindowRate = 1 and SlidingWindowDuration = 2 minutes, the system still sends 2 messages within the 2-minute window. This indicates that the sliding window logic in internal/manager/pipe.go is not enforcing the rate limit correctly.

Steps to Reproduce

  1. Change performence settings to :
    Set all settings to 1 and
    SlidingWindow = true
    SlidingWindowRate = 1
    SlidingWindowDuration = 2m
  2. Add at least 2 subscribers.
  3. Run the campaign and observe message dispatch.

Expected Behavior

Only 1 message should be sent per 2-minute window.

Actual Behavior

2 messages are sent within the same 2-minute window.

Relevant Code Section

hasSliding := p.m.cfg.SlidingWindow &&
    p.m.cfg.SlidingWindowRate > 0 &&
    p.m.cfg.SlidingWindowDuration.Seconds() > 1

...

if hasSliding {
    diff := time.Since(p.m.slidingStart)

    if diff >= p.m.cfg.SlidingWindowDuration {
        p.m.slidingStart = time.Now()
        p.m.slidingCount = 0
        continue
    }

    p.m.slidingCount++
    if p.m.slidingCount >= p.m.cfg.SlidingWindowRate {
        wait := p.m.cfg.SlidingWindowDuration - diff

        p.m.log.Printf("messages exceeded (%d) for the window (%v since %s). Sleeping for %s.",
            p.m.slidingCount,
            p.m.cfg.SlidingWindowDuration,
            p.m.slidingStart.Format(time.RFC822Z),
            wait.Round(time.Second)*1)

        p.m.slidingCount = 0
        time.Sleep(wait)
    }
}

Additional Notes

The issue seems to be with p.m.slidingCount being incremented before checking the limit and/or the continue statements allowing more messages to pass in the same window.

Likely occurs because the first message increments slidingCount and the check happens after the message has already been queued.

Environment

Version: 5.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions