Skip to content

fix: PDX-2459 avoid parallel cache-misses on the same token#17

Merged
arnecls merged 20 commits intomainfrom
block-parallel-requests
Feb 13, 2026
Merged

fix: PDX-2459 avoid parallel cache-misses on the same token#17
arnecls merged 20 commits intomainfrom
block-parallel-requests

Conversation

@arnecls
Copy link
Copy Markdown
Contributor

@arnecls arnecls commented Feb 10, 2026

When a lot of requests for the same token come in at the same time, hitting a cold cache, each request will trigget a cache miss.

In severe cases, this can lead to rate limiting.

This change introduces a FIFO, lock based queue based on the token ID to tackle this problem. The locks may time out based on request context and return a 429 (overloaded, come back later).

@arnecls arnecls requested review from a team and mzjulian as code owners February 10, 2026 11:17
@arnecls arnecls self-assigned this Feb 10, 2026
@github-actions github-actions Bot added 🐞 bug Something that is not working as intended 🔀 metadata-server Affects the metadata-server codebase and removed 🐞 bug Something that is not working as intended labels Feb 10, 2026
@arnecls arnecls added 🐞 bug Something that is not working as intended and removed 🔀 metadata-server Affects the metadata-server codebase labels Feb 10, 2026
@github-actions github-actions Bot added the 🔀 metadata-server Affects the metadata-server codebase label Feb 10, 2026
@qgoulart qgoulart requested a review from Copilot February 10, 2026 11:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Introduces a per-token FIFO ticket lock to prevent parallel cache misses for the same token, reducing thundering-herd behavior and downstream rate limiting.

Changes:

  • Added a TicketLock (FIFO lock with context-aware cancellation) and a uint64 min-heap for tracking canceled tickets.
  • Updated access token handler to serialize same-token cache-miss fetches and return 429 on lock acquisition timeout.
  • Extended token cache with a per-token inflight lock map.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
internal/shared/ticketlock.go Adds FIFO ticket lock with canceled-ticket tracking to avoid parallel cache misses.
internal/shared/intheap.go Adds HeapUint64 to support min-heap operations for canceled tickets.
internal/shared/ticketlock_test.go Adds a basic unit test for ticket allocation, cancellation, and unlock behavior.
cmd/metadata-server/tokencache.go Adds inflight lock map and accessor to retrieve per-token locks.
cmd/metadata-server/tokenhandlers.go Uses per-token lock on cache miss and returns 429 when lock can’t be acquired.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/shared/ticketlock.go Outdated
Comment thread internal/shared/ticketlock.go Outdated
Comment thread internal/shared/ticketlock.go
Comment thread cmd/metadata-server/tokencache.go Outdated
Comment thread cmd/metadata-server/tokencache.go
Comment thread cmd/metadata-server/tokenhandlers.go Outdated
Comment thread cmd/metadata-server/tokenhandlers.go
Comment thread internal/shared/ticketlock_test.go
Comment thread cmd/metadata-server/tokencache.go Outdated
arnecls and others added 2 commits February 10, 2026 15:53
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Arne Claus <arne.claus@gmail.com>
@qgoulart qgoulart requested review from Copilot and qgoulart February 11, 2026 10:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/metadata-server/tokencache.go
Comment thread cmd/metadata-server/tokencache.go
Comment thread internal/shared/ticketlock.go Outdated
Comment thread internal/shared/ticketlock.go
Comment thread internal/shared/ticketlock_test.go
@arnecls arnecls requested a review from Copilot February 11, 2026 13:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/metadata-server/tokencache.go Outdated
Comment thread internal/shared/ticketlock.go Outdated
Comment thread internal/shared/ticketlock_test.go
Comment thread internal/shared/ticketlock_test.go
Comment thread internal/shared/ticketlock_test.go
@arnecls arnecls requested a review from Copilot February 11, 2026 13:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/metadata-server/tokencache.go
Comment thread cmd/metadata-server/tokencache.go Outdated
Comment thread internal/shared/ticketlock.go Outdated
Comment thread cmd/metadata-server/tokencache.go
Comment thread internal/shared/ticketlock.go Outdated
Comment thread internal/shared/ticketlock_test.go Outdated
arnecls and others added 2 commits February 11, 2026 15:10
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Arne Claus <arne.claus@gmail.com>
qgoulart
qgoulart previously approved these changes Feb 11, 2026
@arnecls arnecls requested review from Copilot and qgoulart February 11, 2026 16:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/shared/ticketlock_test.go
Comment thread internal/shared/ticketlock_test.go
@arnecls arnecls requested a review from Copilot February 12, 2026 10:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/shared/ticketlock.go
Comment thread internal/shared/ticketlock.go
Comment thread internal/shared/ticketlock.go
Comment thread internal/shared/ticketlock_test.go
@github-actions
Copy link
Copy Markdown
Contributor

Merging this branch will not change overall coverage

Impacted Packages Coverage Δ 🤖
github.com/trivago/identity-metadata-server/cmd/metadata-server 0.00% (ø)
github.com/trivago/identity-metadata-server/internal/shared 0.00% (ø)

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/trivago/identity-metadata-server/cmd/metadata-server/tokencache.go 0.00% (ø) 0 0 0
github.com/trivago/identity-metadata-server/cmd/metadata-server/tokenhandlers.go 0.00% (ø) 0 0 0
github.com/trivago/identity-metadata-server/internal/shared/intheap.go 0.00% (ø) 0 0 0
github.com/trivago/identity-metadata-server/internal/shared/ticketlock.go 0.00% (ø) 0 0 0

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/trivago/identity-metadata-server/cmd/metadata-server/tokencache_test.go
  • github.com/trivago/identity-metadata-server/internal/shared/ticketlock_test.go

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/shared/ticketlock_test.go
Comment thread internal/shared/ticketlock_test.go
Comment thread internal/shared/ticketlock_test.go Outdated
Comment thread cmd/metadata-server/tokencache.go
Comment thread internal/shared/ticketlock_test.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Arne Claus <arne.claus@gmail.com>
@github-actions
Copy link
Copy Markdown
Contributor

Merging this branch will not change overall coverage

Impacted Packages Coverage Δ 🤖
github.com/trivago/identity-metadata-server/cmd/metadata-server 0.00% (ø)
github.com/trivago/identity-metadata-server/internal/shared 0.00% (ø)

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/trivago/identity-metadata-server/cmd/metadata-server/tokencache.go 0.00% (ø) 0 0 0
github.com/trivago/identity-metadata-server/cmd/metadata-server/tokenhandlers.go 0.00% (ø) 0 0 0
github.com/trivago/identity-metadata-server/internal/shared/intheap.go 0.00% (ø) 0 0 0
github.com/trivago/identity-metadata-server/internal/shared/ticketlock.go 0.00% (ø) 0 0 0

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/trivago/identity-metadata-server/cmd/metadata-server/tokencache_test.go
  • github.com/trivago/identity-metadata-server/internal/shared/ticketlock_test.go

1 similar comment
@github-actions
Copy link
Copy Markdown
Contributor

Merging this branch will not change overall coverage

Impacted Packages Coverage Δ 🤖
github.com/trivago/identity-metadata-server/cmd/metadata-server 0.00% (ø)
github.com/trivago/identity-metadata-server/internal/shared 0.00% (ø)

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/trivago/identity-metadata-server/cmd/metadata-server/tokencache.go 0.00% (ø) 0 0 0
github.com/trivago/identity-metadata-server/cmd/metadata-server/tokenhandlers.go 0.00% (ø) 0 0 0
github.com/trivago/identity-metadata-server/internal/shared/intheap.go 0.00% (ø) 0 0 0
github.com/trivago/identity-metadata-server/internal/shared/ticketlock.go 0.00% (ø) 0 0 0

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/trivago/identity-metadata-server/cmd/metadata-server/tokencache_test.go
  • github.com/trivago/identity-metadata-server/internal/shared/ticketlock_test.go

@arnecls arnecls merged commit a6b2491 into main Feb 13, 2026
13 of 14 checks passed
@arnecls arnecls deleted the block-parallel-requests branch February 13, 2026 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something that is not working as intended 🔀 metadata-server Affects the metadata-server codebase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants