diff --git a/src/server.py b/src/server.py index e2d4939..cad9811 100644 --- a/src/server.py +++ b/src/server.py @@ -434,8 +434,9 @@ def handle_sigint(): def configure_asyncio_event_loop(): """Configure the appropriate event loop based on the platform""" if platform.system() == 'Windows': - # Windows specific configuration - loop = asyncio.ProactorEventLoop() + # Windows specific configuration for aiodns compatibility + asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) + loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) else: # Unix-like systems configuration @@ -465,7 +466,16 @@ def run_server(): except KeyboardInterrupt: handle_sigint() finally: - loop.close() + try: + # Clean up pending tasks + pending = asyncio.all_tasks(loop) + for task in pending: + task.cancel() + # Give tasks a chance to clean up + if pending: + loop.run_until_complete(asyncio.gather(*pending, return_exceptions=True)) + finally: + loop.close() if __name__ == "__main__":