Skip to content

fix: return counter snapshot from LocalStore.incr - #470

Merged
Tony133 merged 1 commit into
fastify:mainfrom
hoanle0126:fix/local-store-pipelined-requests-469
Nov 2, 2026
Merged

Tony133 merged 1 commit into
fastify:mainfrom
hoanle0126:fix/local-store-pipelined-requests-469

Conversation

@hoanle0126

Copy link
Copy Markdown
Contributor

Checklist

Description

Fixes #469

LocalStore.prototype.incr previously passed the mutable current object stored in this.lru directly to cb(null, current). Because applyRateLimit awaits the promise wrapping store.incr(...), concurrent or pipelined requests arriving in the same event-loop turn mutate ++current.current on the shared reference before any request resumes after await. When a pipelined batch exceeds max, all requests in the batch read the final mutated res.current value and fail with 429 instead of only the requests that exceed max.

This change returns a snapshot { current: current.current, ttl: current.ttl } from LocalStore.prototype.incr (consistent with LocalStore.prototype.read and RedisStore.prototype.incr) and adds a regression test for #469.

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Tony133 Tony133 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Tony133
Tony133 merged commit cc8b481 into fastify:main Nov 2, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LocalStore rejects all pipelined requests when the batch exceeds max

3 participants