@@ -915,16 +915,28 @@ def get_integration(
915
915
916
916
return self .integrations .get (integration_name )
917
917
918
+ def _close_transport (self ) -> Optional [asyncio .Task [None ]]:
919
+ """Close transport and return cleanup task if any."""
920
+ if self .transport is not None :
921
+ cleanup_task = self .transport .kill ()
922
+ self .transport = None
923
+ return cleanup_task
924
+ return None
925
+
918
926
def _close_components (self ) -> None :
919
927
"""Kill all client components in the correct order."""
920
928
self .session_flusher .kill ()
921
929
if self .log_batcher is not None :
922
930
self .log_batcher .kill ()
923
931
if self .monitor :
924
932
self .monitor .kill ()
925
- if self .transport is not None :
926
- self .transport .kill ()
927
- self .transport = None
933
+
934
+ async def _close_components_async (self ) -> None :
935
+ """Async version of _close_components that properly awaits transport cleanup."""
936
+ self ._close_components ()
937
+ cleanup_task = self ._close_transport ()
938
+ if cleanup_task is not None :
939
+ await cleanup_task
928
940
929
941
def close ( # type: ignore[override]
930
942
self ,
@@ -941,7 +953,7 @@ async def _flush_and_close(
941
953
) -> None :
942
954
943
955
await self ._flush_async (timeout = timeout , callback = callback )
944
- self ._close_components ()
956
+ await self ._close_components_async ()
945
957
946
958
if self .transport is not None :
947
959
if isinstance (self .transport , AsyncHttpTransport ):
@@ -959,6 +971,8 @@ async def _flush_and_close(
959
971
else :
960
972
self .flush (timeout = timeout , callback = callback )
961
973
self ._close_components ()
974
+ self ._close_transport ()
975
+
962
976
return None
963
977
964
978
def flush ( # type: ignore[override]
0 commit comments