Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EndpointCache #3156

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Fix EndpointCache #3156

wants to merge 1 commit into from

Conversation

MarcusSmith
Copy link

EndpointCache's get(on: Request) convenience function was calling through directly to download, which was completely bypassing the cache. Updated this function to call through to get(using: Client, on: EventLoop) instead which should check cache correctly.

Before this get merged, anyone else running into this can work around the bug by calling cache.get(using: request.client, on: request.eventLoop) instead of cache.get(on: request)

…he other get instead of download, which was bypassing the cache
Copy link
Member

@gwynne gwynne left a comment

Choose a reason for hiding this comment

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

At a glance, this does look correct to me, but I'm not fully familiar with this particular logic; @0xTim can you chime in?

In the meantime, @MarcusSmith can you add a test to EndpointCacheTests.swift for this issue?

@gwynne gwynne added bug Something isn't working semver-patch Internal changes only labels Mar 7, 2024
Copy link

codecov bot commented Mar 7, 2024

Codecov Report

Attention: Patch coverage is 0% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 76.86%. Comparing base (3a7da19) to head (491091a).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3156   +/-   ##
=======================================
  Coverage   76.86%   76.86%           
=======================================
  Files         211      211           
  Lines        8119     8119           
=======================================
  Hits         6241     6241           
  Misses       1878     1878           
Files Coverage Δ
Sources/Vapor/HTTP/EndpointCache.swift 63.07% <0.00%> (ø)

@MarcusSmith
Copy link
Author

MarcusSmith commented Mar 8, 2024

Is there a recommended way to get ahold of a Request in a test to pass into it?

Best I've been able to come up with is define a new middleware that uses an endpoint cache for something and trigger that multiple times through a get request and assert that it only calls that cache's endpoint once. But I'm unsure of how I'd be able to make those assertions

Just did a live test of our hackaround to use the other init and it fixed our production issue, so I'm pretty confident this was the issue

@0xTim
Copy link
Member

0xTim commented Mar 14, 2024

@MarcusSmith you can stub out the client with something similar to #2928 to make it possible to make assertions on that (and avoid any network requests)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working semver-patch Internal changes only
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants