背景
微服务一模块调用另一模块报错
feign.RetryableException: Incomplete output stream executing POST
翻译:执行POST的输出流不完整
解决办法
pom.xml中加入依赖
<dependency><groupId>io.github.openfeign</groupId><artifactId>feign-httpclient</artifactId>
</dependency>
yml文件最好配置成用okhttp&#xff0c;性能会更好些。
feign:okhttp:enabled: trueclient:config:default:loggerLevel: full
原因
根据异常调用链得知最终发生车祸的是sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1523) HttpURLConnection.getInputStream0方法1523行。经过搜索资料&#xff0c;原来feign采用jdk原生HttpURLConnection向下游服务发起http请求&#xff08;源码详见feign.Client.Default&#xff09;&#xff0c;先到getInputStream0方法看看&#xff1a;
private synchronized InputStream getInputStream0() throws IOException {if(!this.doInput) {throw new ProtocolException("Cannot read from URLConnection if doInput&#61;false (call setDoInput(true))");} else if(this.rememberedException !&#61; null) {if(this.rememberedException instanceof RuntimeException) {throw new RuntimeException(this.rememberedException);} else {throw this.getChainedException((IOException)this.rememberedException);}} else if(this.inputStream !&#61; null) {return this.inputStream;} else {if(this.streaming()) {if(this.strOutputStream &#61;&#61; null) {this.getOutputStream();}this.strOutputStream.close();if(!this.strOutputStream.writtenOK()) { throw new IOException("Incomplete output stream"); }}..........boolean writtenOK() {return this.closed && !this.error;}
看起来&#xff0c;this.error是true导致的&#xff0c;也就是说在OutputStream写入流时出错。
参考
feign.RetryableException: Incomplete output stream executing POST
https://blog.csdn.net/weixin_42397269/article/details/106112619
Feign 报异常IOException Incomplete output stream
https://www.jianshu.com/p/6397e2cd1fae