From 8f7be87b1e94deb2bf4413d0b68a00e21ecda848 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Fri, 19 Aug 2016 17:40:07 +0200 Subject: [PATCH] Use timemout for project auto close to avoid issue when client / connect --- .../handlers/api/controller/project_handler.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/gns3server/handlers/api/controller/project_handler.py b/gns3server/handlers/api/controller/project_handler.py index 91ff62ae..914cebac 100644 --- a/gns3server/handlers/api/controller/project_handler.py +++ b/gns3server/handlers/api/controller/project_handler.py @@ -213,8 +213,12 @@ class ProjectHandler: except asyncio.futures.CancelledError as e: break - if project.auto_close and not controller.notification.project_has_listeners(project): - yield from project.close() + if project.auto_close: + # To avoid trouble with client connecting disconnecting we sleep few seconds before checking + # if someone else is not connected + yield from asyncio.sleep(5) + if not controller.notification.project_has_listeners(project): + yield from project.close() @Route.get( r"/projects/{project_id}/notifications/ws", @@ -247,8 +251,12 @@ class ProjectHandler: break ws.send_str(notification) - if project.auto_close and not controller.notification.project_has_listeners(project): - yield from project.close() + if project.auto_close: + # To avoid trouble with client connecting disconnecting we sleep few seconds before checking + # if someone else is not connected + yield from asyncio.sleep(5) + if not controller.notification.project_has_listeners(project): + yield from project.close() return ws