Tornado curl_httpclient 'reset' connection

人盡茶涼 提交于 2019-12-13 03:56:10

问题


I have a tornado application that makes requests to an http server using curl_httpclient. Every once in a while, all calls to the server returns incorrect results. In other words, the http responses are still fine, but the contents returned by the server becomes incorrect.

I find I can get around this problem by terminating and restarting my process, which seems to mean that if I make a new TCP connection to the server and send new requests, things will be fine.

Now my problem is how to make HTTP requests over a new TCP connection. I tried to replace the http client with a new one like below, but it seems that a new TCP connection is not made and the old connection reused.

http_client = tornado.httpclient.AsyncHTTPClient()

How can I close my existing TCP connection and make a new connection to the server and continue the business?


回答1:


You can pass the force_instance=True keyword argument to the AsyncHTTPClient constructor to ensure that you get a new object instead of reusing an old one, but it's probably worth figuring out why you're getting "incorrect" results in the first place.

How are the results "incorrect"? Is it not a well-formed HTTP response? Is it a response for an earlier (or subsequent pipelined) request on the same connection, or something unrelated?

Make sure you're using an up-to-date version of libcurl - very old versions had a history of problems with the asynchronous interfaces, although I haven't seen any problems in a couple of years. Note that if you're on a slow-moving distribution like centos this may mean installing libcurl from source instead of getting it from your distribution. If you don't have a specific need for curl_httpclient you can also use tornado's simple_httpclient instead.



来源:https://stackoverflow.com/questions/21499722/tornado-curl-httpclient-reset-connection

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!