wb.ouyang

毕竟几人真得鹿,不知终日梦为鱼

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

grpc(二)记一次grpc debug--io.grpc.StatusRuntimeException: UNKNOWN

1、起初是dingding一直报错:

instance:服务器名
err:GrpcClient#placeOrder: io.grpc.StatusRuntimeException: UNKNOWN

 

2、定位错误位置(找到问题,复现问题

  上面标红的代码是调用dingding,所以可以确定是调用grpc时,grpc内部报错,所以返回status message为 UNKNOWN

复制代码
public Object placeOrder(Integer uid, 其他参数) {

        PlaceOrderRequest request = PlaceOrderRequest.newBuilder().setUserid(uid).build();
        GrpcReply response;

        try {
            response = tradeBlockingStub.placeOrder(request);
            UtilFunctions.log.info("GrpcClient#placeOrder rusult: code:{}, data:{}", 
                    response.getCode(), response.getData());
            return response;
        } catch (StatusRuntimeException e) {
            UtilFunctions.log.error("GrpcClient#placeOrder: msg:{}, exception:{}", e.toString(), e);
            UtilFunctions.reportError("GrpcClient#placeOrder: " + e.toString(), e);
            return null;
        }
    }
复制代码

  

  查看linux上的日志,发现controller接收的数据price为NaN。

 

  所以,我在本地给price参数传NaN进行测试,果然出现同样的错误。grpc报错,原因是给Double类型的参数传了NaN,打印信息:

四月 10, 2019 1:20:48 下午 io.grpc.internal.SerializingExecutor run
严重: Exception while executing runnable io.grpc.internal.ServerImpl$JumpToApplicationThreadServerStreamListener$1HalfClosed@2d37b2d0
java.lang.NumberFormatException

  

 3、解决

  在controller对Double类型的数据进行判断。

Double obj;
obj.isNaN();

 

4、测试前台传NaN数据

  4.1、新建一个springboot项目(版本2.1.3)

  4.2、application.properties

server.port=8090
server.servlet.context-path=/

  4.3、IndexController.java

复制代码
@RestController
public class IndexController {

    @RequestMapping("/index")
    public Object demo1(Double price, Integer num) {
        // 前端给price传NaN是可以的
        // ==== price: NaN ====
        if (price.isNaN()) {
            System.out.println("---- price.isNaN ----");
        }
        System.out.println("==== price: " + price + " ====");
        System.out.println(price.getClass().getName());

        System.out.println("==== num: " + num + " ====");
        System.out.println(num.getClass().getName());

        Map<String, Object> result = new HashMap<>();
        result.put("price", price);
        result.put("num", num);

        return result;
    }
}
复制代码

 

  4.4、使用firefox测试

 

posted on   wenbin_ouyang  阅读(13892)  评论(0编辑  收藏  举报

编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示