Skip to content

Commit 25c04fc

Browse files
committed
ref(client): Fix transport shutdown if loop is not running
GH-4601
1 parent 6df7037 commit 25c04fc

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

sentry_sdk/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ def get_integration(
918918
def _close_transport(self) -> Optional[asyncio.Task[None]]:
919919
"""Close transport and return cleanup task if any."""
920920
if self.transport is not None:
921-
cleanup_task = self.transport.kill()
921+
cleanup_task = self.transport.kill() # type: ignore
922922
self.transport = None
923923
return cleanup_task
924924
return None
@@ -963,7 +963,9 @@ async def _flush_and_close(
963963
_flush_and_close(timeout, callback)
964964
)
965965
except RuntimeError:
966+
# Shutdown the components anyway
966967
self._close_components()
968+
self._close_transport()
967969
logger.warning("Event loop not running, aborting close.")
968970
return None
969971
# Enforce flush before shutdown

sentry_sdk/transport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ def _make_pool(
781781

782782
return httpcore.AsyncConnectionPool(**opts)
783783

784-
def kill(self: Self) -> Optional[asyncio.Task[None]]: # type: ignore
784+
def kill(self: Self) -> Optional[asyncio.Task[None]]: # type: ignore[override]
785785

786786
logger.debug("Killing HTTP transport")
787787
self._worker.kill()

0 commit comments

Comments
 (0)