Skip to content

Commit d94e127

Browse files
committed
attempt to send CLOSE message on connection close
1 parent ea46b38 commit d94e127

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎ably/realtime/connectionmanager.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,13 @@ async def close_impl(self) -> None:
175175
self.cancel_suspend_timer()
176176
self.start_transition_timer(ConnectionState.CLOSING, fail_state=ConnectionState.CLOSED)
177177
if self.transport:
178-
await self.transport.dispose()
178+
# Try to send protocol CLOSE message to server for clean shutdown
179+
# If connection is already broken, continue with dispose anyway
180+
try:
181+
await self.transport.close()
182+
except Exception as e:
183+
log.debug(f'ConnectionManager.close_impl(): failed to send CLOSE message: {e}')
184+
await self.transport.dispose() # Dispose transport resources
179185
if self.connect_base_task:
180186
self.connect_base_task.cancel()
181187
if self.disconnect_transport_task:

0 commit comments

Comments
 (0)