@@ -68,19 +68,6 @@ def __init__(self, url: str) -> None:
68
68
Create a new `TimestampAuthorityClient` from the given URL.
69
69
"""
70
70
self .url = url
71
- self .session = requests .Session ()
72
- self .session .headers .update (
73
- {
74
- "Content-Type" : "application/timestamp-query" ,
75
- "User-Agent" : USER_AGENT ,
76
- }
77
- )
78
-
79
- def __del__ (self ) -> None :
80
- """
81
- Terminates the underlying network session.
82
- """
83
- self .session .close ()
84
71
85
72
def request_timestamp (self , signature : bytes ) -> TimeStampResponse :
86
73
"""
@@ -104,9 +91,18 @@ def request_timestamp(self, signature: bytes) -> TimeStampResponse:
104
91
msg = f"invalid request: { error } "
105
92
raise TimestampError (msg )
106
93
94
+ # Use single use session to avoid potential Session thread safety issues
95
+ session = requests .Session ()
96
+ session .headers .update (
97
+ {
98
+ "Content-Type" : "application/timestamp-query" ,
99
+ "User-Agent" : USER_AGENT ,
100
+ }
101
+ )
102
+
107
103
# Send it to the TSA for signing
108
104
try :
109
- response = self . session .post (
105
+ response = session .post (
110
106
self .url ,
111
107
data = timestamp_request .as_bytes (),
112
108
timeout = CLIENT_TIMEOUT ,
0 commit comments