Fix unclosed Session file descriptor leak in RequestsClient (fixes #874)#1798
Fix unclosed Session file descriptor leak in RequestsClient (fixes #874)#1798Jah-yee wants to merge 1 commit intostripe:masterfrom
Conversation
…ripe#874) Register atexit handler to close thread-local Session when Python exits. The Session created in _thread_local is never closed, causing ResourceWarning and socket file descriptor leaks. Fix: add atexit.register(self.close) in RequestsClient.__init__. Ref: stripe#874
|
Gentle ping @richardlawrence @ob-stripe @cjavilla-stripe — this PR fixes unclosed Session file descriptor leak in RequestsClient (fixes #874). Looking forward to your review! 🙏 |
|
Hi! Just following up on this PR. The fix addresses an unclosed file descriptor leak in RequestsClient (issue #874). CI is green. Happy to make any adjustments if needed! |
|
Thank you for the submission! We'll have to take a look to see if the performance characteristics mentioned in the original issue have changed since it was filed. That may take us some time, since there's a lot else on our plate right now. |
|
Friendly ping @jar-stripe — just checking in on this PR. Happy to make any adjustments if needed! 🙏 |
|
@Jah-yee I've already replied above- please stop pinging maintainers. |
Summary
Fixes file descriptor / socket leak in
stripe-pythonwhen using therequestsclient.Problem
The
RequestsClientstores arequests.Sessionin a thread-local variable (self._thread_local.session). This Session is created on first use but never closed, causing:ResourceWarning: unclosed <ssl.SSLSocket>on Python exitSolution
Register
atexit.register(self.close)inRequestsClient.__init__()to ensure the thread-local Session is properly closed when Python exits.Changes
stripe/_http_client.py:import atexitatexit.register(self.close)inRequestsClient.__init__Testing
References
requestsleaks socket file descriptors via unclosed Session #874requestsleaks socket file descriptors via unclosed Session #874