org.apache.http.ConnectionClosedException: Premature end of Content-Length delimited message body

Detailed map traversal, teach you to master the complex gremlin query debugging method>>>

Send an HTTP request to the back-end service and report an error when there is a large amount of data:

org.apache.http.ConnectionClosedException: Premature end of Content-Length delimited message body (expected: 144445481; Received: 25370248)
it means that the data transmission has been terminated ahead of time. 144445481 B is expected to be transmitted, but 25370248 B is transmitted

The HTTP request model is shown in the table above. When the client accesses the service with the IP and port of the server, even if there is a large amount of data, there is no problem. But once through the domain name access, that is, through nginx access, a large amount of data will report the above error. In fact, nginx limits the response result. If the nginx timeout is set short and the buffer is large, you can modify the nginx timeout and increase the time. In this way, in the process of large data transmission, it will not be terminated because of timeout. If the nginx timeout is long enough, but the buffer is small, you can increase the buffer to solve the problem

Another point to note is that the problem of synchronization and asynchrony may cause this problem, such as:

method A{

Sentence 1

Statement 2 (call other database queries asynchronously)

Statement 3 (finally block closes connection)

}

In the above logic, if method a is called synchronously, but the database query is asynchronous, one possible situation is that the data transmission is not completed, but statement 3 has been executed, and the connection is closed, which may also cause the above problem

Author: anickname
source: CSDN
original text: https://blog.csdn.net/javajxz008/article/details/82684479
Copyright notice: This article is the original article of the blogger, please attach the blog link if you reprint it

Similar Posts: