Skip to content

Simplify MCP catalog loading: single fetch per run with ETag caching#2124

Merged
dgageot merged 1 commit intodocker:mainfrom
dgageot:board/look-at-the-mcp-gateway-code-and-find-pl-0251e8c8
Mar 16, 2026
Merged

Simplify MCP catalog loading: single fetch per run with ETag caching#2124
dgageot merged 1 commit intodocker:mainfrom
dgageot:board/look-at-the-mcp-gateway-code-and-find-pl-0251e8c8

Conversation

@dgageot
Copy link
Member

@dgageot dgageot commented Mar 16, 2026

Replace the complex multi-layered catalog caching (RWMutex, background refresh goroutine, stale-while-revalidate, double-checked locking) with a straightforward single-fetch design:

  • Fetch the catalog at most once per process via sync.OnceValues, using context.Background() so that a short-lived caller context cannot permanently poison the cached result.
  • Use HTTP ETag / If-None-Match for conditional requests (304 fast path).
  • Fall back to the disk cache on any network failure.
  • Write the disk cache atomically (temp file + rename) so that a crash mid-write cannot leave a corrupt file for the next run.
  • Add a 15 s context timeout on the HTTP request, replacing the unbounded http.Get.
  • Use paths.GetCacheDir() instead of a hand-rolled ~/.cagent path.
  • Fetch the JSON variant of the catalog URL (≈3× faster to parse) once at init time instead of rebuilding the string on every call.

Assisted-By: docker-agent

@dgageot dgageot requested a review from a team as a code owner March 16, 2026 14:22
docker-agent[bot]

This comment was marked as outdated.

Replace the complex multi-layered catalog caching (RWMutex, background
refresh goroutine, stale-while-revalidate, double-checked locking) with
a straightforward single-fetch design:

- Fetch the catalog at most once per process via sync.OnceValues,
  using context.Background() so that a short-lived caller context
  cannot permanently poison the cached result.
- Use HTTP ETag / If-None-Match for conditional requests (304 fast path).
- Fall back to the disk cache on any network failure.
- Write the disk cache atomically (temp file + rename) so that a crash
  mid-write cannot leave a corrupt file for the next run.
- Add a 15 s context timeout on the HTTP request, replacing the
  unbounded http.Get.
- Use paths.GetCacheDir() instead of a hand-rolled ~/.cagent path.
- Fetch the JSON variant of the catalog URL (≈3× faster to parse)
  once at init time instead of rebuilding the string on every call.

Assisted-By: docker-agent
@dgageot dgageot force-pushed the board/look-at-the-mcp-gateway-code-and-find-pl-0251e8c8 branch from c517fb9 to d6db654 Compare March 16, 2026 15:44
@dgageot dgageot merged commit f678e03 into docker:main Mar 16, 2026
4 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.

2 participants