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 property caching #9313

Merged
merged 2 commits into from
May 26, 2023
Merged

Fix property caching #9313

merged 2 commits into from
May 26, 2023

Conversation

yawkat
Copy link
Member

@yawkat yawkat commented May 26, 2023

This fixes the build broken by #9310. Basically:

['spec.name': StaticClientFilterSpec.simpleName,
'test-port': '${random.port}',
'micronaut.server.port': '${test-port}',
'micronaut.http.services.a.url': 'http://localhost:${test-port}',
'micronaut.http.services.b.url': 'http://localhost:${test-port}',

The resolution of micronaut.server.port used to request the value of test-port as String. With this patch, it requests the value as Object instead (.getValue(Object.class)). The caching in PropertySourcePropertyResolver depends on the requested type however, so the Object request (micronaut.server.port) and the String request (micronaut.http.services.a.url) are cached separately and have different computed ports. (Additionally Object request type is not cached at all, but this is not the core issue.)

This patch adds another cache before conversion that is independent of the requested type. This cache ensures that the value is not recomputed for different request types.

This fixes the build broken by #9310. Basically:

https://github.com/micronaut-projects/micronaut-core/blob/94f458ac04b0180a989d0cf28984d5e3b5df592f/http-client/src/test/groovy/io/micronaut/http/client/filter/StaticClientFilterSpec.groovy#L24-L28

The resolution of micronaut.server.port used to request the value of test-port as String. With this patch, it requests the value as Object instead (`.getValue(Object.class)`). The caching in PropertySourcePropertyResolver depends on the requested type however, so the Object request (micronaut.server.port) and the String request (micronaut.http.services.a.url) are cached separately and have different computed ports. (Additionally Object request type is not cached at all, but this is not the core issue.)

This patch adds another cache *before* conversion that is independent of the requested type. This cache ensures that the value is not recomputed for different request types.
@yawkat yawkat requested a review from graemerocher May 26, 2023 08:09
@sonarcloud
Copy link

sonarcloud bot commented May 26, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@graemerocher graemerocher merged commit f21a3cf into 4.0.x May 26, 2023
7 checks passed
@graemerocher graemerocher deleted the cachefix2 branch May 26, 2023 09:24
@dstepanov dstepanov added the type: bug Something isn't working label May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants