recurly-client-python icon indicating copy to clipboard operation
recurly-client-python copied to clipboard

Recreate HTTPSConnection after errors

Open dgilmanAIDENTIFIED opened this issue 3 years ago • 6 comments

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.

dgilmanAIDENTIFIED avatar Jun 16 '22 13:06 dgilmanAIDENTIFIED

This would also probably fix https://github.com/recurly/recurly-client-python/issues/378

ridersofrohan avatar Aug 17 '22 19:08 ridersofrohan

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.

dgilmanAIDENTIFIED avatar Jun 27 '23 20:06 dgilmanAIDENTIFIED

@bhelx - will this be implemented - I just ran into a similar problem.

davidemerritt avatar Jul 05 '23 19:07 davidemerritt

@davidemerritt i haven't worked for Recurly since 2020. So pinging @douglasmiller for this issue.

bhelx avatar Jul 05 '23 19:07 bhelx

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.

bhelx avatar Jul 05 '23 19:07 bhelx

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

davidemerritt avatar Jul 05 '23 21:07 davidemerritt