splunk-sdk-python icon indicating copy to clipboard operation
splunk-sdk-python copied to clipboard

poor connection management results in errors with http connections that are kept alive

Open cjw296 opened this issue 11 years ago • 5 comments

This line can close the connection before the response has finished reading from it:

https://github.com/splunk/splunk-sdk-python/blob/master/splunklib/binding.py#L1341

This happens when the connection has kept a reference to the response:

https://hg.python.org/cpython/file/v2.7.5/Lib/httplib.py#l782

The conditions under which this case happen are covered by the code in HTTPResponse.begin (look for will_close):

https://hg.python.org/cpython/file/v2.7.5/Lib/httplib.py#l402

The connection should not be closed in this way.

cjw296 avatar Oct 22 '15 13:10 cjw296

Thanks for the bug report @cjw296, we are open to a pull request to address the problem

shakeelmohamed avatar Oct 27 '15 02:10 shakeelmohamed

Well, I submitted a pull request for another bug 11 days ago, which has had zero attention...

cjw296 avatar Oct 27 '15 05:10 cjw296

Woops, my mistake. We'll look into this

shakeelmohamed avatar Oct 27 '15 06:10 shakeelmohamed

@cjw296 thank you for the bug report, and I apologize for taking so long to reply.

The answer is that I am not sure your analysis is correct, but I am not sure it is wrong either. Both the Python source code and the Python documentation are not clear on these points. Specifically, as far as I can tell from both debugging into the Python source and from reading it is that calling close on the connection is fine, as it will keep the socket open while there are responses pending.

That said, I want to make sure I understand your issue. Specifically, which of these are you saying:

  1. That the way we're closing the connection is wrong because we shouldn't close it prior to reading the response?
  2. That the way we're closing the connection is fine, but it makes Keep-Alive not work?

If it's (2), that may very well be the case, but I think (1) is not the case - our logic is correct. I just want to make sure we're investigating the right problem.

Finally, do you have a test script that shows the problem you are having? That will help us tremendously in fixing it.

itay avatar Nov 21 '15 01:11 itay

@itay - the analysis is correct, the problem shows itself if you put an HAProxy load balancer in front of a Splunk search head pool.

However, given the poor quality of this software, I'd suggest you just recommend users write their own Python client libraries layered over the requests library and rely on REST API direct rather than the poor recommendations of this library's documentation and the unattended and serious failings it contains.

cjw296 avatar Nov 22 '15 21:11 cjw296