diff --git a/sanic/server.py b/sanic/server.py index 0b82f1d3..0d7809d3 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -636,7 +636,9 @@ def serve(host, port, request_handler, error_handler, before_start=None, coros = [] for conn in connections: if hasattr(conn, "websocket") and conn.websocket: - coros.append(conn.websocket.close_connection(force=True)) + coros.append( + conn.websocket.close_connection(after_handshake=True) + ) else: conn.close() diff --git a/sanic/worker.py b/sanic/worker.py index 79c0a17d..3d8a4617 100644 --- a/sanic/worker.py +++ b/sanic/worker.py @@ -115,7 +115,9 @@ class GunicornWorker(base.Worker): coros = [] for conn in self.connections: if hasattr(conn, "websocket") and conn.websocket: - coros.append(conn.websocket.close_connection(force=True)) + coros.append( + conn.websocket.close_connection(after_handshake=False) + ) else: conn.close() _shutdown = asyncio.gather(*coros, loop=self.loop) diff --git a/setup.py b/setup.py index 17f2c67e..3f8cd7ce 100644 --- a/setup.py +++ b/setup.py @@ -59,7 +59,7 @@ requirements = [ uvloop, ujson, 'aiofiles>=0.3.0', - 'websockets>=3.2', + 'websockets>=4.0', ] if strtobool(os.environ.get("SANIC_NO_UJSON", "no")): print("Installing without uJSON") diff --git a/tests/test_worker.py b/tests/test_worker.py index e2b301ec..af00982e 100644 --- a/tests/test_worker.py +++ b/tests/test_worker.py @@ -131,5 +131,5 @@ def test_worker_close(worker): loop.run_until_complete(_close) assert worker.signal.stopped == True - conn.websocket.close_connection.assert_called_with(force=True) + conn.websocket.close_connection.assert_called_with(after_handshake=False) assert len(worker.servers) == 0