poor connection management results in errors with http connections that are kept alive
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.
Thanks for the bug report @cjw296, we are open to a pull request to address the problem
Well, I submitted a pull request for another bug 11 days ago, which has had zero attention...
Woops, my mistake. We'll look into this
@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:
- That the way we're closing the connection is wrong because we shouldn't close it prior to reading the response?
- 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 - 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.