Skip to content

Backends: counter overflow in increment() behaves differently on Redis, Memcached and memory #364

Description

@allen0099

Found during the docs audit (#359). The docs now describe the per-backend ranges; the behaviour at the edge still differs.

Backend Incrementing past the range
Redis raises a raw redis.exceptions.ResponseError ("increment or decrement would overflow"). backends/redis.py:435-439 only converts the "not an integer" error to CacheXError
Memcached wraps around silently: counter_entry(2**64 - 1) incremented by 1 returns 0
Memory grows past 64 bits without limit

validate_delta already limits delta to signed 64-bit, but the resulting value is unchecked.

Proposal

Make overflow one documented behaviour on every backend, most likely CacheXError (Redis: also convert the overflow ResponseError; Memcached: detect the wrap, e.g. compare against the previous value, or document unsigned 64-bit as its range and reject values that would wrap; Memory: bound to signed 64-bit). Decide whether this is a fix for a patch release or a behaviour change for 0.4.0. Tests per backend.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendsCache backends and their atomic primitivesbugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions