Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http api server connection close 无连接复用也无 response header connection close 导致 client 使用已经被 server 半关闭的连接 #2428

Closed
1 task done
lindzh opened this issue Feb 16, 2023 · 1 comment

Comments

@lindzh
Copy link

lindzh commented Feb 16, 2023

  • 我已经在 issues 里搜索,没有重复的issue。

环境信息

  • java httpclient4 使用连接池调用 arthas http api

重现问题的步骤

  1. java httpclient4 使用连接池调用本地 arthas http api。
  2. 请求 response 返回后,在 2s 内发送第二次请求。
  3. 第二次请求失败。
String url = "http://127.0.0.1:8563/api";
String body = "{\n" +
    "  \"action\":\"exec\",\n" +
    "  \"command\":\"version\"\n" +
    "}";
for (int i = 0; i < 2; i++) {
    try{
        HttpResponseMeta meta = httpComponent.httpPost(url, null, null, body);
        System.out.println(meta.getResponseAsString());
        Thread.sleep(1000);
    }catch (Throwable e){
        e.printStackTrace();
    }
}

期望的结果

第二次连接复用的请求能够成功。
如果不复用连接,第一次的 response 需要带上 connection:close 符合 http 协议连接优雅关闭。

实际运行的结果

实际运行结果,最好有详细的日志,异常栈。尽量贴文本。

{"body":{"command":"version","jobId":4,"jobStatus":"TERMINATED","results":[{"jobId":4,"type":"version","version":"3.5.4"},{"jobId":4,"statusCode":0,"type":"status"}],"timeExpired":false},"sessionId":"ddd458e3-b4f1-47f9-b261-b9dbf7310dab","state":"SUCCEEDED"}
[2023-02-16 14:14:45.463] ERROR http exception:127.0.0.1:8563 failed to respond
org.apache.http.NoHttpResponseException: 127.0.0.1:8563 failed to respond
	at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:143)
	at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
	at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259)
	at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:163)
	at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:167)
	at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273)
	at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125)
	at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:271)
	at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
	at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)

bug 代码位置

@lindzh lindzh changed the title http api server connection close 无连接复用也无 response header connection close 导致 client 使用已经reset 的链接 http api server connection close 无连接复用也无 response header connection close 导致 client 使用已经被 server 半关闭的连接 Feb 16, 2023
@hengyunabc
Copy link
Collaborator

image

补张图。

欢迎提交pr修复。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants