Kubernetes上SpringBoot应用初始化DaprClientBuilder时触发致命错误
问题描述
我有两个打包为Docker镜像的SpringBoot应用运行在Kubernetes(microk8s)环境中,尝试通过DaprClient让第一个应用调用第二个应用的HTTP服务。应用部署状态正常,Dapr控制台显示健康且两个应用已注册,但在执行代码行DaprClient daprClient = (new DaprClientBuilder()).build();时失败,错误发生在客户端初始化阶段,早于invoke调用。我已交叉验证端口,但问题仍未解决,希望能得到方向指引。
orderservice的deployment.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: ordersystem labels: app: ordersystem spec: selector: matchLabels: app: ordersystem template: metadata: labels: app: ordersystem annotations: dapr.io/enabled: "true" dapr.io/app-id: "ordersystem" dapr.io/app-port: "8082" spec: containers: - name: ordersystem image: localhost:5000/ordersystem:latest ports: - containerPort: 8082
出错的Java代码片段
错误发生在打印"About to initialize daprClient"之后、"Dapr client init worked"之前,说明是初始化阶段出错:
@Override public List<OrderJoinDTO> findAllOrdersDetails() { List<OrderJoinDTO> orderDTO = (List<OrderJoinDTO>) ordersRepo.findAllOrdersDetails(); for(OrderJoinDTO order: orderDTO) { System.out.println("Fething productInfo from DAPR app products for orderId: "+order.getOrderId()+" with productId: "+order.getProductsId()); try { System.out.println("About to initialize daprClient, please wait"); DaprClient daprClient = (new DaprClientBuilder()).build(); // invoke a 'GET' method (HTTP) skipping serialization: \say with a Mono<byte[]> return type System.out.println("Dapr client init worked, proceeding to invoking"); Products response = daprClient.invokeMethod("products", "findByProductsId/"+order.getProductsId(), null, HttpExtension.GET, Products.class).block(); System.out.println("Retrived from DAPR: "+response.toString()); order.setPname(response.getPname()); order.setDescription(response.getDescription()); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } return orderDTO; }
Kubernetes控制台错误信息
2022-11-08 09:46:33.619 INFO 1 --- [nio-8082-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 2 ms Hibernate: select orders0_.orderId as col_0_0_, users1_.userName as col_1_0_, users1_.address as col_2_0_, users1_.email as col_3_0_, userpaymen2_.paymentType as col_4_0_, orders_pro3_.productsId as col_5_0_ from Orders orders0_ cross join Users users1_ cross join UserPayments userpaymen2_ cross join Orders_Products_MAP orders_pro3_ where orders0_.userId=users1_.userId and orders0_.paymentId=userpaymen2_.paymentId and orders0_.orderId=orders_pro3_.orderId Fething productInfo from DAPR app products for orderId: 1 with productId: 1 About to initialize daprClient, please wait # # A fatal error has been detected by the Java Runtime Environment: # # SIGSEGV (0xb) at pc=0x0000000000003efe, pid=1, tid=0x00007f0eb58cbb10 # # JRE version: OpenJDK Runtime Environment (8.0_212-b04) (build 1.8.0_212-b04) # Java VM: OpenJDK 64-Bit Server VM (25.212-b04 mixed mode linux-amd64 compressed oops) # Derivative: IcedTea 3.12.0 # Distribution: Custom build (Sat May 4 17:33:35 UTC 2019) # Problematic frame: # C 0x0000000000003efe # # Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again # # An error report file with more information is saved as: # //hs_err_pid1.log # # If you would like to submit a bug report, please include # instructions on how to reproduce the bug and visit: # https://icedtea.classpath.org/bugzilla #
排查方向建议
- 检查Dapr Java SDK与JDK版本兼容性:你当前使用的JDK 8u212版本过旧,部分新版本Dapr Java SDK已不再支持该版本。建议升级JDK至8u301及以上,或直接切换到JDK11,同时确保Dapr SDK版本与JDK版本匹配。
- 重构DaprClient实例创建逻辑:不要在循环内重复创建DaprClient实例,这会导致资源占用异常。应将DaprClient作为单例管理,比如通过Spring的
@Bean注解全局初始化,在需要的地方注入使用。 - 检查Dapr Sidecar通信状态:进入ordersystem的Pod,查看Dapr sidecar日志,确认其是否正常监听默认gRPC端口(50001);同时检查Pod内的环境变量,确认
DAPR_GRPC_PORT等Dapr相关变量是否正确注入。 - 读取JVM崩溃日志详情:错误提示生成了
hs_err_pid1.log文件,进入Pod内部读取该文件,里面包含的详细堆栈信息能定位到导致段错误(SIGSEGV)的具体原因。 - 验证Dapr SDK依赖配置:检查项目pom.xml或build.gradle中的Dapr SDK依赖,确保无遗漏、无版本冲突,且SDK版本与集群中Dapr版本兼容。
内容的提问来源于stack exchange,提问作者vick_4444
相关产品推荐
相关产品推荐

