[英]java.net.SocketException: Broken pipe (Write failed) while posting json payload to rest api
Getting java.net.SocketException: Broken pipe (Write failed) while sending json payload arround size of 3.2 mb in size but its intermittent.获取 java.net.SocketException: Broken pipe (Write failed),同时发送 json 有效负载大小为 3.2 mb 的大小,但它是间歇性的。 However for small size it's working.
但是对于小尺寸它是有效的。 The code is running on jetty server.
代码在 jetty 服务器上运行。
I thought there may be memory issue after upgrading server memory with heap size arround 7GB and verified while running this job memory and cpu utilization was normal but still it is failing.我认为在使用大约 7GB 的堆大小升级服务器内存后可能会出现内存问题,并在运行此作业时验证内存和 CPU 利用率正常但仍然失败。
Also we try with modifying below sysctl setting on jetty server but still no luck sometimes get processed successfully but from few days it continously failing.此外,我们尝试在码头服务器上修改以下 sysctl 设置,但有时仍然没有运气成功处理,但几天后它不断失败。
sysctl -w net.core.rmem_max=16777216 sysctl -w
net.core.wmem_max=16777216 sysctl -w net.ipv4.tcp_rmem="4096 87380
16777216" sysctl -w net.ipv4.tcp_wmem="4096 16384 16777216" sysctl
-w net.core.somaxconn=4096 sysctl -w net.core.netdev_max_backlog=16384 sysctl -w net.ipv4.tcp_max_syn_backlog=8192
Below is code that we are using to call rest api:下面是我们用来调用rest api的代码:
RestClient restTemplate = null;
HttpEntity<String> entity = new HttpEntity<String>(payload, headers);
ResponseEntity<String> responseEntity = null;try
{
restTemplate = new RestClient(null, null, accessKey, secretKey);
responseEntity = restTemplate.exchange(url, method, entity, String.class);
return responseEntity;
}catch(
Exception ex)
{
}
// contructor setting
public RestClient(final String proxyHost, final String proxyPort, final String username, final String password) {
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(null, -1), new UsernamePasswordCredentials(username, password));
HttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient));
}
Any idea how i can fix this issue, i am struggling past more than 20 days.知道如何解决这个问题,我挣扎了 20 多天。 Please let me know if you need any more input.
如果您需要更多输入,请告诉我。
After going through lots of articals.在经历了很多文章之后。 Now, I have found a solution to the problem.
现在,我找到了解决问题的方法。 This is caused by:
这是由以下原因引起的:
I found one useful artical here : https://blog.stackpath.com/glossary-keep-alive/我在这里找到了一篇有用的文章: https : //blog.stackpath.com/glossary-keep-alive/
It is working only by just adding in header below line:它仅通过在行下方添加标题来工作:
headers.add(new BasicHeader(HttpHeaders.CONNECTION, "close")); headers.add(new BasicHeader(HttpHeaders.CONNECTION, "close"));
Hi I have a similiar issue but my error is only on prod environment not on the local or test environment so I cannot be sure that your solution it will work for me.嗨,我有一个类似的问题,但我的错误仅在生产环境中,而不是在本地或测试环境中,所以我无法确定您的解决方案是否适合我。 So can you check my error is same with your error.
所以你能检查我的错误与你的错误相同吗? You can check my error here :
你可以在这里检查我的错误:
Broken pipe (Write failed) while posting json payload to rest api 将 json 有效负载发布到 rest api 时管道损坏(写入失败)
Thank you谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.