一、起初是dingding一直報錯:前端
instance:服務器名 err:GrpcClient#placeOrder: io.grpc.StatusRuntimeException: UNKNOWN
二、定位錯誤位置(找到問題,復現問題)java
上面標紅的代碼是調用dingding,因此能夠肯定是調用grpc時,grpc內部報錯,因此返回status message爲 UNKNOWN。linux
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。spring
因此,我在本地給price參數傳NaN進行測試,果真出現一樣的錯誤。grpc報錯,緣由是給Double類型的參數傳了NaN,打印信息:springboot
四月 10, 2019 1:20:48 下午 io.grpc.internal.SerializingExecutor run 嚴重: Exception while executing runnable io.grpc.internal.ServerImpl$JumpToApplicationThreadServerStreamListener$1HalfClosed@2d37b2d0 java.lang.NumberFormatException
三、解決服務器
在controller對Double類型的數據進行判斷。app
Double obj; obj.isNaN();
四、測試前臺傳NaN數據測試
4.一、新建一個springboot項目(版本2.1.3)ui
4.二、application.propertiesspa
server.port=8090 server.servlet.context-path=/
4.三、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.四、使用firefox測試