并发调用api时发生异常

问题描述

单击一次可以正常工作,但是当日志增加时,所有请求开始失败

在每个请求中,我正在调用另一个应用程序,该应用程序以500ms的延迟进行响应,然后在获得响应后,我将从db中获取用户。

      @RequestMapping(value = "/{userId}",method = RequestMethod.GET)
        public Mono<User> getUser(@PathVariable String userId) {
                        return sendRequestWithApacheHttpClient(500)
                                .flatMap(s-> userRepository.findById(userId));
        }

         private Mono<String> sendRequestWithApacheHttpClient(long delay) {
 WebClient   client=WebClient.create(userServiceHost);
                return client.get().uri("/other/?delay="+delay)
                        .accept(MediaType.TEXT_PLAIN)
                        .retrieve().bodyToMono(String.class);
         }

处理并发请求时出错。

20-08-25 05:51:17.909 ERROR 15726 --- [or-http-epoll-3] a.w.r.e.AbstractErrorWebExceptionHandler : [a9f12668-3777]  500 Server Error for HTTP GET "/user/5f3e7c44465eca51

io.netty.channel.ChannelException: io.netty.channel.unix.Errors$NativeIoException: newSocketStream(..) failed: Too many open files
        at io.netty.channel.unix.Socket.newSocketStream0(Socket.java:421) ~[netty-transport-native-unix-common-4.1.50.Final.jar:4.1.50.Final]
        Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
        |_ checkpoint ⇢ Handler com.user.reactive.controller.UserController#getUser(String) [DispatcherHandler]
        |_ checkpoint ⇢ HTTP GET "/user/5f3e7c44465eca5131363d65" [ExceptionHandlingWebHandler]
Stack trace:
                at io.netty.channel.unix.Socket.newSocketStream0(Socket.java:421) ~[netty-transport-native-unix-common-4.1.50.Final.jar:4.1.50.Final]
                at io.netty.channel.epoll.LinuxSocket.newSocketStream(LinuxSocket.java:319) ~[netty-transport-native-epoll-4.1.50.Final-linux-x86_64.jar:4.1.50.Final]

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...