Skip to content

Commit 543c028

Browse files
committed
prevent orphaned tcp socket
1 parent de62932 commit 543c028

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

httpcore/_async/connection.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ async def _connect(self, request: Request) -> AsyncNetworkStream:
143143
"timeout": timeout,
144144
}
145145
async with Trace("connection.start_tls", request, kwargs) as trace:
146-
stream = await stream.start_tls(**kwargs)
146+
try:
147+
stream = await stream.start_tls(**kwargs)
148+
except Exception:
149+
await stream.aclose()
150+
raise
147151
trace.return_value = stream
148152
return stream
149153

httpcore/_sync/connection.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ def _connect(self, request: Request) -> NetworkStream:
143143
"timeout": timeout,
144144
}
145145
with Trace("connection.start_tls", request, kwargs) as trace:
146-
stream = stream.start_tls(**kwargs)
146+
try:
147+
stream = stream.start_tls(**kwargs)
148+
except Exception:
149+
stream.close()
150+
raise
147151
trace.return_value = stream
148152
return stream
149153

0 commit comments

Comments
 (0)