Skip to content

SQS: purge_queue never raises PurgeQueueInProgress within the 60 second window #10233

Closed

Description

@haeganm

SQS purge_queue never raises PurgeQueueInProgress. Real SQS allows only one PurgeQueue operation per queue every 60 seconds; a second call inside that window fails with error code AWS.SimpleQueueService.PurgeQueueInProgress. Moto happily purges any number of times, so code that handles (or tests for) the purge cooldown behaves differently against moto than against AWS.

The 60 second rule is in the PurgeQueue API reference ("Only one PurgeQueue operation is allowed every 60 seconds"), and the botocore service model declares the PurgeQueueInProgress error shape on the operation: "Indicates that the specified queue previously received a PurgeQueue request within the last 60 seconds (the time it can take to delete the messages in the queue)."
https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_PurgeQueue.html

Repro:

import boto3
from moto import mock_aws

@mock_aws
def repro():
    client = boto3.client("sqs", region_name="us-east-1")
    queue_url = client.create_queue(QueueName="t1")["QueueUrl"]
    client.purge_queue(QueueUrl=queue_url)
    client.purge_queue(QueueUrl=queue_url)  # succeeds; AWS raises PurgeQueueInProgress
    print("second purge succeeded")

repro()

Against real AWS the second call raises ClientError with code AWS.SimpleQueueService.PurgeQueueInProgress and message Only one PurgeQueue operation on t1 is allowed every 60 seconds.; against moto it prints second purge succeeded.

Versions: moto 5.2.4.dev (master), boto3 1.40.x, Python 3.12.

I have a fix ready (track the last purge time on the queue and raise the documented error inside the window) and will open a PR. One note for the discussion: this makes moto stricter, so a user test suite that purges the same queue repeatedly without mocking time would start seeing the same error real AWS gives; happy to gate it behind a setting instead if you prefer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions