Skip to content

Commit 064d24c

Browse files
committed
timestamp: Dont reuse session
It's a little unclear if Session is now thread safe or not: avoid reuse just in case Signed-off-by: Jussi Kukkonen <[email protected]>
1 parent e8e0298 commit 064d24c

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

sigstore/_internal/timestamp.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,6 @@ def __init__(self, url: str) -> None:
6868
Create a new `TimestampAuthorityClient` from the given URL.
6969
"""
7070
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()
8471

8572
def request_timestamp(self, signature: bytes) -> TimeStampResponse:
8673
"""
@@ -104,9 +91,18 @@ def request_timestamp(self, signature: bytes) -> TimeStampResponse:
10491
msg = f"invalid request: {error}"
10592
raise TimestampError(msg)
10693

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+
107103
# Send it to the TSA for signing
108104
try:
109-
response = self.session.post(
105+
response = session.post(
110106
self.url,
111107
data=timestamp_request.as_bytes(),
112108
timeout=CLIENT_TIMEOUT,

0 commit comments

Comments
 (0)