Recreate HTTPSConnection after errors
This is a fix to #556
If a network error happens when self.__conn.request is called the underlying HTTPSConnection is left in a bad state. If you're trying to retry errors the next request raises a CannotSendRequest when you get to the next self.__conn.request call.
This PR keeps track of successful self.__conn.getrequest() calls and resets the connection object if a previous request was not successful.
This would also probably fix https://github.com/recurly/recurly-client-python/issues/378
We've been using this in production for a year now successfully so I hope this can be merged as it fixes what was for us a frequent issue. I am going to leave this PR open in hopes the Recurly team can take it over and merge the fix. However, I am no longer going to maintain it as we are no longer Recurly customers.
@bhelx - will this be implemented - I just ran into a similar problem.
@davidemerritt i haven't worked for Recurly since 2020. So pinging @douglasmiller for this issue.
Just a note: resetting the connection every call seems kind of extreme. Perhaps you can just catch the exception CannotSendRequest, recreate the connection, then retry the request.
But there could be some deeper problem worth looking into.
thanks @bhelx!
@douglasmiller - I would expect that the client = recurly.Client(settings.RECURLY_API_KEY) client setup would handle connection pooling and be persistent. If it starts breaking at a certain point in production then we have no way to re-initialize this since it is created as a singleton. Would be great for this to be addressed. Thank you