Skip to content

Commit 17d0374

Browse files
committed
fix: session isolation
1 parent 94f518c commit 17d0374

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

common/http_timing.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,14 @@ async def measure_http_request_timing(
101101
"""
102102
timing_collector = HttpTimingCollector()
103103
trace_config: aiohttp.TraceConfig = timing_collector.create_trace_config()
104-
105-
# Freeze trace config before adding to session
106104
trace_config.freeze()
107-
# Add timing trace to session temporarily
108-
session._trace_configs.append(trace_config)
109105

110-
try:
106+
# Create new session with isolated trace config
107+
connector = session._connector
108+
timeout = session._timeout
109+
async with aiohttp.ClientSession(
110+
connector=connector, timeout=timeout, trace_configs=[trace_config]
111+
) as isolated_session:
111112
response = None
112113
last_exception = None
113114

@@ -122,7 +123,7 @@ async def measure_http_request_timing(
122123
request_kwargs["json"] = json_data
123124

124125
# Send request with consistent method handling
125-
response = await session.request(method.upper(), url, **request_kwargs)
126+
response = await isolated_session.request(method.upper(), url, **request_kwargs)
126127

127128
# Handle rate limiting with exponential backoff
128129
if response.status == 429 and retry_count < MAX_RETRIES - 1:
@@ -155,11 +156,6 @@ async def measure_http_request_timing(
155156
)
156157
return response_time, response
157158

158-
finally:
159-
# Remove trace config to avoid affecting other requests
160-
if trace_config in session._trace_configs:
161-
session._trace_configs.remove(trace_config)
162-
163159

164160
async def make_json_rpc_request(
165161
session: aiohttp.ClientSession,

0 commit comments

Comments
 (0)