From 341b2da496ef1e722605ce1d4f074036f08873e9 Mon Sep 17 00:00:00 2001 From: Jah-yee <166608075+Jah-yee@users.noreply.github.com> Date: Sun, 26 Apr 2026 20:21:56 +0800 Subject: [PATCH] Fix unclosed Session file descriptor leak in RequestsClient (fixes #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: https://github.com/stripe/stripe-python/issues/874 --- stripe/_http_client.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stripe/_http_client.py b/stripe/_http_client.py index 4fb246523..132ce4eaa 100644 --- a/stripe/_http_client.py +++ b/stripe/_http_client.py @@ -1,4 +1,5 @@ from io import BytesIO +import atexit import textwrap import email import time @@ -603,6 +604,7 @@ def __init__( _lib = requests self.requests = _lib + atexit.register(self.close) def request( self,