提问人:Bob Redity 提问时间:2/26/2022 更新时间:12/8/2022 访问量:842
java.lang.IllegalStateException:查询 GraphQL 后的递归更新
java.lang.IllegalStateException: Recursive update after making query to GraphQL
问:
我正在对graphQL进行查询,但出现此异常
java.lang.IllegalStateException: Recursive update
at java.base/java.util.concurrent.ConcurrentHashMap.compute(ConcurrentHashMap.java:1983)
at com.github.benmanes.caffeine.cache.BoundedLocalCache.doComputeIfAbsent(BoundedLocalCache.java:2373)
at com.github.benmanes.caffeine.cache.BoundedLocalCache.computeIfAbsent(BoundedLocalCache.java:2356)
at com.github.benmanes.caffeine.cache.LocalCache.computeIfAbsent(LocalCache.java:108)
at com.github.benmanes.caffeine.cache.LocalManualCache.get(LocalManualCache.java:62)
at io.micronaut.cache.caffeine.DefaultSyncCache.get(DefaultSyncCache.java:134)
at io.micronaut.cache.interceptor.CacheInterceptor.interceptSync(CacheInterceptor.java:172)
at io.micronaut.cache.interceptor.CacheInterceptor.intercept(CacheInterceptor.java:136)
at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:96)
at com.mydomain.bff.$OAuthServiceDefinition$Intercepted.authToken(Unknown Source)
at com.mydomain.bff.$OAuthService.scoreCard(OAuthService.kt:55)
at com.mydomain.bff.$OAuthServiceDefinition$Intercepted.$$access$$scoreCard(Unknown Source)
at com.mydomain.bff.$OAuthServiceDefinition$$exec2.invokeInternal(Unknown Source)
at io.micronaut.context.AbstractExecutableMethod.invoke(AbstractExecutableMethod.java:151)
at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:87)
at io.micronaut.cache.interceptor.CacheInterceptor.doContextProceed(CacheInterceptor.java:484)
at io.micronaut.cache.interceptor.CacheInterceptor.doProceed(CacheInterceptor.java:488)
at io.micronaut.cache.interceptor.CacheInterceptor.lambda$interceptSync$2(CacheInterceptor.java:174)
at io.micronaut.cache.caffeine.DefaultSyncCache.lambda$get$0(DefaultSyncCache.java:134)
at com.github.benmanes.caffeine.cache.BoundedLocalCache.lambda$doComputeIfAbsent$14(BoundedLocalCache.java:2375)
at java.base/java.util.concurrent.ConcurrentHashMap.compute(ConcurrentHashMap.java:1908)
at com.github.benmanes.caffeine.cache.BoundedLocalCache.doComputeIfAbsent(BoundedLocalCache.java:2373)
at com.github.benmanes.caffeine.cache.BoundedLocalCache.computeIfAbsent(BoundedLocalCache.java:2356)
at com.github.benmanes.caffeine.cache.LocalCache.computeIfAbsent(LocalCache.java:108)
at com.github.benmanes.caffeine.cache.LocalManualCache.get(LocalManualCache.java:62)
at io.micronaut.cache.caffeine.DefaultSyncCache.get(DefaultSyncCache.java:134)
at io.micronaut.cache.interceptor.CacheInterceptor.interceptSync(CacheInterceptor.java:172)
at io.micronaut.cache.interceptor.CacheInterceptor.intercept(CacheInterceptor.java:136)
at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:96)
at com.mydomain.bff.$OAuthServiceDefinition$Intercepted.scoreCard(Unknown Source)
at com.mydomain.bff.getScoreCard(ApigeeResolver.kt:16)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at graphql.kickstart.tools.resolver.MethodFieldResolverDataFetcher.get(MethodFieldResolver.kt:261)
at graphql.execution.ExecutionStrategy.fetchField(ExecutionStrategy.java:270)
at graphql.execution.ExecutionStrategy.resolveFieldWithInfo(ExecutionStrategy.java:203)
at graphql.execution.AsyncExecutionStrategy.execute(AsyncExecutionStrategy.java:60)
at graphql.execution.Execution.executeOperation(Execution.java:165)
at graphql.execution.Execution.execute(Execution.java:104)
at graphql.GraphQL.execute(GraphQL.java:557)
at graphql.GraphQL.parseValidateAndExecute(GraphQL.java:482)
at graphql.GraphQL.executeAsync(GraphQL.java:446)
at io.micronaut.configuration.graphql.DefaultGraphQLInvocation.lambda$null$0(DefaultGraphQLInvocation.java:86)
at io.micronaut.core.async.publisher.CompletableFuturePublisher$CompletableFutureSubscription.request(CompletableFuturePublisher.java:76)
at io.reactivex.internal.operators.flowable.FlowableFlatMap$InnerSubscriber.onSubscribe(FlowableFlatMap.java:656)
at io.micronaut.core.async.publisher.CompletableFuturePublisher.subscribe(CompletableFuturePublisher.java:47)
at io.reactivex.internal.operators.flowable.FlowableFlatMap$MergeSubscriber.onNext(FlowableFlatMap.java:163)
at io.micronaut.reactive.rxjava2.RxInstrumentedSubscriber.onNext(RxInstrumentedSubscriber.java:59)
at io.micronaut.core.async.publisher.Publishers$JustPublisher$1.request(Publishers.java:519)
at io.reactivex.internal.operators.flowable.FlowableFlatMap$MergeSubscriber.onSubscribe(FlowableFlatMap.java:117)
at io.micronaut.reactive.rxjava2.RxInstrumentedSubscriber.onSubscribe(RxInstrumentedSubscriber.java:52)
at io.micronaut.core.async.publisher.Publishers$JustPublisher.subscribe(Publishers.java:509)
at io.reactivex.internal.operators.flowable.FlowableFromPublisher.subscribeActual(FlowableFromPublisher.java:29)
at io.reactivex.Flowable.subscribe(Flowable.java:14918)
at io.reactivex.Flowable.subscribe(Flowable.java:14865)
at io.micronaut.reactive.rxjava2.RxInstrumentedFlowable.subscribeActual(RxInstrumentedFlowable.java:57)
at io.reactivex.Flowable.subscribe(Flowable.java:14918)
at io.reactivex.internal.operators.flowable.FlowableFlatMap.subscribeActual(FlowableFlatMap.java:53)
at io.reactivex.Flowable.subscribe(Flowable.java:14918)
at io.reactivex.Flowable.subscribe(Flowable.java:14868)
at io.micronaut.core.async.publisher.Publishers.lambda$map$3(Publishers.java:205)
at io.micronaut.core.async.publisher.Publishers.lambda$map$3(Publishers.java:205)
at io.micronaut.core.async.publisher.Publishers.lambda$mapOrSupplyEmpty$4(Publishers.java:246)
at io.micronaut.http.server.netty.RoutingInBoundHandler.emitRouteResponse(RoutingInBoundHandler.java:1566)
at io.micronaut.http.server.netty.RoutingInBoundHandler.access$2100(RoutingInBoundHandler.java:151)
at io.micronaut.http.server.netty.RoutingInBoundHandler$6$1.request(RoutingInBoundHandler.java:1469)
at io.reactivex.internal.subscriptions.SubscriptionHelper.deferredSetOnce(SubscriptionHelper.java:202)
at io.reactivex.internal.operators.single.SingleFlatMapPublisher$SingleFlatMapPublisherObserver.onSubscribe(SingleFlatMapPublisher.java:107)
at io.micronaut.http.server.netty.RoutingInBoundHandler$6.doSubscribe(RoutingInBoundHandler.java:1457)
at io.micronaut.http.server.netty.RoutingInBoundHandler$6.lambda$subscribe$0(RoutingInBoundHandler.java:1451)
at io.micronaut.scheduling.instrument.InvocationInstrumenterWrappedRunnable.run(InvocationInstrumenterWrappedRunnable.java:47)
at io.micrometer.core.instrument.composite.CompositeTimer.record(CompositeTimer.java:79)
at io.micrometer.core.instrument.Timer.lambda$wrap$0(Timer.java:160)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
该错误意味着什么? 我正在为 android 应用程序开发 BFF 部分。在安卓方面,我之前做过定期的改造请求。现在,我将该 API 调用移动到 bff 层,并使用相同的数据类和请求结构。但是遇到了那个我不明白的奇怪错误。您能否指导如何解决?
答:
1赞
Sai Srikar Mutya
12/8/2022
#1
我们在以下逻辑中遇到了类似的问题,
Repository 类
@Cacheable(DATA_CACHE_NAME)
public SomeData retrieveData(String id) {
return retrieveDataForCacheRefresh(id);
}
public SomeData retrieveDataForCacheRefresh(String id) {
// get from the data store
}
配置类
LoadingCache<Object, Object> cache = Caffeine.newBuilder()
.build(key -> repository.**retrieveData**(key));
此问题的原因是,而不是调用
repository.**retrieveDataForCacheRefresh**
我们在打电话
repository.**retrieveData**
因此,数据刷新再次调用 @Cacheable 方法,这会导致递归更新问题。
所以正确的做法是,
LoadingCache<Object, Object> cache = Caffeine.newBuilder()
.build(key -> repository.retrieveDataForCacheRefresh(key));
希望它能:)
评论