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

nacos ERROR [ForkJoinPool.commonPool-worker-1] naming: [NA] failed to write cache for dom:xxx java.io.IOException: file not exist #12004

Closed
SirZiWang opened this issue Apr 23, 2024 · 5 comments

Comments

@SirZiWang
Copy link

version
naocos server 2.1.1
nacos client 2.1.1
spring-cloud-alibaba.version 2022.0.0.0-RC1
spring-boot version 3.0.5
spring-cloud version 2022.0.0

Describe the bug
2024-04-23 10:28:04,065 ERROR [ForkJoinPool.commonPool-worker-1] naming: [NA] failed to write cache for dom:xxx-detect
java.io.IOException: file not exist
at com.alibaba.nacos.client.naming.cache.ConcurrentDiskUtil.writeFileContent(ConcurrentDiskUtil.java:163)
at com.alibaba.nacos.client.naming.cache.DiskCache.write(DiskCache.java:75)
at com.alibaba.nacos.client.naming.cache.ServiceInfoHolder.processServiceInfo(ServiceInfoHolder.java:173)
at com.alibaba.nacos.client.naming.remote.NamingClientProxyDelegate.subscribe(NamingClientProxyDelegate.java:175)
at com.alibaba.nacos.client.naming.NacosNamingService.selectInstances(NacosNamingService.java:311)
at com.alibaba.nacos.client.naming.NacosNamingService.selectInstances(NacosNamingService.java:281)
at com.alibaba.nacos.client.naming.NacosNamingService.selectInstances(NacosNamingService.java:269)
at com.alibaba.cloud.nacos.discovery.NacosServiceDiscovery.getInstances(NacosServiceDiscovery.java:58)
at com.alibaba.cloud.nacos.discovery.NacosDiscoveryClient.getInstances(NacosDiscoveryClient.java:62)
at org.springframework.cloud.client.discovery.composite.CompositeDiscoveryClient.getInstances(CompositeDiscoveryClient.java:53)
at org.springframework.cloud.loadbalancer.core.DiscoveryClientServiceInstanceListSupplier.lambda$new$0(DiscoveryClientServiceInstanceListSupplier.java:64)
at reactor.core.publisher.MonoCallable$MonoCallableSubscription.request(MonoCallable.java:137)
at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.request(Operators.java:2305)
at reactor.core.publisher.SerializedSubscriber.request(SerializedSubscriber.java:151)
at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.set(Operators.java:2341)
at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onSubscribe(FluxOnErrorResume.java:74)
at reactor.core.publisher.SerializedSubscriber.onSubscribe(SerializedSubscriber.java:65)
at reactor.core.publisher.FluxTimeout$TimeoutMainSubscriber.onSubscribe(FluxTimeout.java:154)
at reactor.core.publisher.MonoCallable.subscribe(MonoCallable.java:48)
at reactor.core.publisher.FluxFromMonoOperator.subscribe(FluxFromMonoOperator.java:83)
at reactor.core.publisher.FluxDefer.subscribe(FluxDefer.java:54)
at reactor.core.publisher.InternalFluxOperator.subscribe(InternalFluxOperator.java:62)
at reactor.core.publisher.FluxDefer.subscribe(FluxDefer.java:54)
at reactor.core.publisher.Mono.subscribe(Mono.java:4485)
at reactor.core.publisher.FluxSwitchIfEmpty$SwitchIfEmptySubscriber.onComplete(FluxSwitchIfEmpty.java:82)
at reactor.core.publisher.Operators.complete(Operators.java:137)
at reactor.core.publisher.MonoEmpty.subscribe(MonoEmpty.java:46)
at reactor.core.publisher.InternalFluxOperator.subscribe(InternalFluxOperator.java:62)
at reactor.core.publisher.FluxDefer.subscribe(FluxDefer.java:54)
at reactor.core.publisher.Mono.subscribe(Mono.java:4485)
at reactor.core.publisher.Mono.block(Mono.java:1709)
at org.springframework.cloud.loadbalancer.blocking.client.BlockingLoadBalancerClient.choose(BlockingLoadBalancerClient.java:160)
at org.springframework.cloud.openfeign.loadbalancer.RetryableFeignBlockingLoadBalancerClient.lambda$execute$2(RetryableFeignBlockingLoadBalancerClient.java:157)
at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:329)
at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:225)
at org.springframework.cloud.openfeign.loadbalancer.RetryableFeignBlockingLoadBalancerClient.execute(RetryableFeignBlockingLoadBalancerClient.java:135)
at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:102)
at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:72)
at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:98)
at org.springframework.cloud.openfeign.FeignCachingInvocationHandlerFactory$1.proceed(FeignCachingInvocationHandlerFactory.java:66)
at org.springframework.cache.interceptor.CacheInterceptor.lambda$invoke$0(CacheInterceptor.java:54)
at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:351)
at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:64)
at org.springframework.cloud.openfeign.FeignCachingInvocationHandlerFactory.lambda$create$1(FeignCachingInvocationHandlerFactory.java:53)
at jdk.proxy2/jdk.proxy2.$Proxy157.beuStart(Unknown Source)
at com.xx.xx.task.service.impl.TaskExecuteAlgServiceImpl.executeAlgAnalysis(TaskExecuteAlgServiceImpl.java:48)
at com.xx.xx.task.strategy.impl.VideoStrategyImpl.lambda$cameraExecute$4(VideoStrategyImpl.java:250)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at com.xx.xx.task.strategy.impl.VideoStrategyImpl.cameraExecute(VideoStrategyImpl.java:229)
at com.xx.xx.task.strategy.impl.VideoStrategyImpl.execTaskPoint(VideoStrategyImpl.java:183)
at com.xx.xx.task.strategy.impl.VideoStrategyImpl.lambda$executeAsyncTask$1(VideoStrategyImpl.java:127)
at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804)
at java.base/java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796)
at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)

Expected behavior
When calling services through feign, services cannot be discovered normally through Naos. Expected normal discovery of access between services.

@SirZiWang
Copy link
Author

Occasionally, this type of error occurs with a high probability

@KomachiSion
Copy link
Collaborator

java.io.IOException: file not exist

Please make sure your disk env is correct. which can let nacos-client read or write cache into disk.

@SirZiWang
Copy link
Author

SirZiWang commented Apr 26, 2024

public static Boolean writeFileContent(File file, String content, String charsetName) throws IOException {
        
        if (!file.exists() && !file.createNewFile()) {
            return false;
        }
        FileChannel channel = null;
        FileLock lock = null;
        RandomAccessFile raf = null;
        try {
            raf = new RandomAccessFile(file, READ_WRITE);
            channel = raf.getChannel();
            int i = 0;
            do {
                try {
                    lock = channel.tryLock();
                } catch (Exception e) {
                    ++i;
                    if (i > RETRY_COUNT) {
                        NAMING_LOGGER.error("[NA] write {} fail;retryed time:{}", file.getName(), i);
                        throw new IOException("write " + file.getAbsolutePath() + " conflict", e);
                    }
                    sleep(SLEEP_BASETIME * i);
                    NAMING_LOGGER.warn("write " + file.getName() + " conflict;retry time: " + i);
                }
            } while (null == lock);
            
            byte[] contentBytes = content.getBytes(charsetName);
            ByteBuffer sendBuffer = ByteBuffer.wrap(contentBytes);
            while (sendBuffer.hasRemaining()) {
                channel.write(sendBuffer);
            }
            channel.truncate(contentBytes.length);
        } catch (FileNotFoundException e) {
            throw new IOException("file not exist");
        } finally {
            if (lock != null) {
                try {
                    lock.release();
                    lock = null;
                } catch (IOException e) {
                    NAMING_LOGGER.warn("close wrong", e);
                }
            }
            if (channel != null) {
                try {
                    channel.close();
                    channel = null;
                } catch (IOException e) {
                    NAMING_LOGGER.warn("close wrong", e);
                }
            }
            if (raf != null) {
                try {
                    raf.close();
                    raf = null;
                } catch (IOException e) {
                    NAMING_LOGGER.warn("close wrong", e);
                }
            }
            
        }
        return true;
    }

This method will actively create files, and when the code is executed, it will report that the file does not exist, which is an occasional error. There is no problem with the permissions of the directory files under the cache directory
@KomachiSion

@KomachiSion
Copy link
Collaborator

But I can't reproduce in my all env, I think it's a env problem so that nacos can't create the dir auto.

@KomachiSion
Copy link
Collaborator

No more response from author, It seems env problem.

@KomachiSion KomachiSion closed this as not planned Won't fix, can't repro, duplicate, stale May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants