From cc6012ffd62dfa1fac8b02aa43930ddf71078035 Mon Sep 17 00:00:00 2001 From: Paolo Di Tommaso Date: Sat, 29 Jun 2024 12:20:21 +0200 Subject: [PATCH] Fix client cache deadlock (#547) Signed-off-by: Paolo Di Tommaso --- .../io/seqera/wave/core/RegistryProxyService.groovy | 2 +- .../groovy/io/seqera/wave/tower/client/TowerClient.groovy | 8 ++++---- src/main/resources/application.yml | 6 +++--- .../seqera/wave/tower/client/TowerClientHttpTest.groovy | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/groovy/io/seqera/wave/core/RegistryProxyService.groovy b/src/main/groovy/io/seqera/wave/core/RegistryProxyService.groovy index a62d2aa71..da1f75db3 100644 --- a/src/main/groovy/io/seqera/wave/core/RegistryProxyService.groovy +++ b/src/main/groovy/io/seqera/wave/core/RegistryProxyService.groovy @@ -200,7 +200,7 @@ class RegistryProxyService { static private List RETRY_ON_NOT_FOUND = HTTP_RETRYABLE_ERRORS + 404 - @Cacheable(value = 'cache-20sec', atomic = true) + @Cacheable(value = 'cache-registry-proxy', atomic = true) protected String getImageDigest0(BuildRequest request, boolean retryOnNotFound) { final image = request.targetImage final coords = ContainerCoordinates.parse(image) diff --git a/src/main/groovy/io/seqera/wave/tower/client/TowerClient.groovy b/src/main/groovy/io/seqera/wave/tower/client/TowerClient.groovy index c0d5aae02..354115424 100644 --- a/src/main/groovy/io/seqera/wave/tower/client/TowerClient.groovy +++ b/src/main/groovy/io/seqera/wave/tower/client/TowerClient.groovy @@ -47,25 +47,25 @@ class TowerClient { return connector.sendAsync(endpoint, uri, authorization, type) } - @Cacheable(value = 'cache-20sec', atomic = true) + @Cacheable(value = 'cache-tower-client', atomic = true) CompletableFuture serviceInfo(String towerEndpoint) { final uri = serviceInfoEndpoint(towerEndpoint) return getAsync(uri, towerEndpoint, null, ServiceInfoResponse) } - @Cacheable(value = 'cache-20sec', atomic = true) + @Cacheable(value = 'cache-tower-client', atomic = true) CompletableFuture userInfo(String towerEndpoint, JwtAuth authorization) { final uri = userInfoEndpoint(towerEndpoint) return getAsync(uri, towerEndpoint, authorization, UserInfoResponse) } - @Cacheable(value = 'cache-20sec', atomic = true) + @Cacheable(value = 'cache-tower-client', atomic = true) CompletableFuture listCredentials(String towerEndpoint, JwtAuth authorization, Long workspaceId) { final uri = listCredentialsEndpoint(towerEndpoint, workspaceId) return getAsync(uri, towerEndpoint, authorization, ListCredentialsResponse) } - @Cacheable(value = 'cache-20sec', atomic = true) + @Cacheable(value = 'cache-tower-client', atomic = true) CompletableFuture fetchEncryptedCredentials(String towerEndpoint, JwtAuth authorization, String credentialsId, String pairingId, Long workspaceId) { final uri = fetchCredentialsEndpoint(towerEndpoint, credentialsId, pairingId, workspaceId) return getAsync(uri, towerEndpoint, authorization, GetCredentialsKeysResponse) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 6e75c6cce..d4906a843 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -6,11 +6,11 @@ micronaut: # IMPORTANT: use `expire-after-write` strategy to guarantee cached entries are not retained more than the declared period. # Using `expire-after-read` can cause an entry to be retained in the cache more than expected if it is hit continuously # with a frequency shorter than the declared cache period. - cache-20sec: + cache-tower-client: expire-after-write: 20s record-stats: true - cache-1min: - expire-after-write: 1m + cache-registry-proxy: + expire-after-write: 20s record-stats: true # Discovery client by default uses a cache for results. This is a transitive behaviour # introduced by prometheus and management dependencies and below line disables as diff --git a/src/test/groovy/io/seqera/wave/tower/client/TowerClientHttpTest.groovy b/src/test/groovy/io/seqera/wave/tower/client/TowerClientHttpTest.groovy index ea70837c3..477edef5d 100644 --- a/src/test/groovy/io/seqera/wave/tower/client/TowerClientHttpTest.groovy +++ b/src/test/groovy/io/seqera/wave/tower/client/TowerClientHttpTest.groovy @@ -131,8 +131,8 @@ class TowerClientHttpTest extends Specification{ def setup() { jwtAuthStore.clear() - cacheManager.getCache("cache-1min").invalidateAll() - cacheManager.getCache("cache-20sec").invalidateAll() + cacheManager.getCache("cache-tower-client").invalidateAll() + cacheManager.getCache("cache-registry-proxy").invalidateAll() towerConnector.refreshCache0().invalidateAll() }