Fix unclosed Session file descriptor leak in RequestsClient (fixes #874)#1798
Open
Jah-yee wants to merge 1 commit intostripe:masterfrom
Open
Fix unclosed Session file descriptor leak in RequestsClient (fixes #874)#1798Jah-yee wants to merge 1 commit intostripe:masterfrom
Jah-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
Author
|
Gentle ping @richardlawrence @ob-stripe @cjavilla-stripe — this PR fixes unclosed Session file descriptor leak in RequestsClient (fixes #874). Looking forward to your review! 🙏 |
Author
|
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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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