Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package python-pycrdt-websocket for 
openSUSE:Factory checked in at 2026-11-20 14:51:55
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-pycrdt-websocket (Old)
 and      /work/SRC/openSUSE:Factory/.python-pycrdt-websocket.new.1251 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "python-pycrdt-websocket"

Fri Nov 20 14:51:55 2026 rev:8 rq:1398954 version:0.16.9

Changes:
--------
--- 
/work/SRC/openSUSE:Factory/python-pycrdt-websocket/python-pycrdt-websocket.changes
  2026-03-23 17:13:19.057548293 +0100
+++ 
/work/SRC/openSUSE:Factory/.python-pycrdt-websocket.new.1251/python-pycrdt-websocket.changes
        2026-11-20 14:53:01.369369094 +0100
@@ -1,0 +2,16 @@
+Thu Nov 19 12:00:00 UTC 2026 - Ana Guerrero <[email protected]>
+
+- Update to 0.16.9
+  * Clean up empty rooms when serving a client fails.
+  * Ensure rooms are initialized before reporting that they have
+    started.
+  * Fix send task exception handling.
+  * Fix concurrent clients joining the same room.
+  * Add `ydoc_observed` event.
+  * Wait for `start()` to return in `WebsocketServer.stop()`.
+  * Unobserve awareness callback in `YRoom.stop`.
+  * Drop Python 3.10 and add Python 3.15.
+  * Bump pycrdt to >=0.14.13,<0.15.0 and pycrdt-store to
+    >=0.1.5,<0.2.0.
+
+-------------------------------------------------------------------

Old:
----
  pycrdt_websocket-0.16.0.tar.gz

New:
----
  pycrdt_websocket-0.16.9.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ python-pycrdt-websocket.spec ++++++
--- /var/tmp/diff_new_pack.0EHW3M/_old  2026-11-20 14:53:02.993437826 +0100
+++ /var/tmp/diff_new_pack.0EHW3M/_new  2026-11-20 14:53:02.995437911 +0100
@@ -1,7 +1,7 @@
 #
 # spec file for package python-pycrdt-websocket
 #
-# Copyright (c) 2025 SUSE LLC and contributors
+# Copyright (c) 2026 SUSE LLC and contributors
 #
 # All modifications and additions to the file contributed by third parties
 # remain the property of their copyright owners, unless otherwise agreed
@@ -25,7 +25,7 @@
 %bcond_with test
 %endif
 Name:           python-pycrdt-websocket%{?psuffix}
-Version:        0.16.0
+Version:        0.16.9
 Release:        0
 Summary:        WebSocket connector for pycrdt
 License:        MIT
@@ -37,10 +37,9 @@
 BuildRequires:  %{python_module pip}
 BuildRequires:  fdupes
 BuildRequires:  python-rpm-macros
-Requires:       python-anyio >= 3.6.2
-Requires:       python-pycrdt-store
-Requires:       (python-pycrdt >= 0.10.3 with python-pycrdt < 0.13)
-Requires:       (python-sqlite-anyio >= 0.2.3 with python-sqlite-anyio < 0.3.0)
+Requires:       (python-anyio >= 3.6.2 with python-anyio < 5)
+Requires:       (python-pycrdt >= 0.14.13 with python-pycrdt < 0.15)
+Requires:       (python-pycrdt-store >= 0.1.5 with python-pycrdt-store < 0.2.0)
 Provides:       python-pycrdt_websocket = %{version}-%{release}
 %if %{with test}
 BuildRequires:  %{python_module httpx-ws >= 0.5.2}

++++++ pycrdt_websocket-0.16.0.tar.gz -> pycrdt_websocket-0.16.9.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/pycrdt_websocket-0.16.0/.github/workflows/publish.yml 
new/pycrdt_websocket-0.16.9/.github/workflows/publish.yml
--- old/pycrdt_websocket-0.16.0/.github/workflows/publish.yml   2020-02-02 
01:00:00.000000000 +0100
+++ new/pycrdt_websocket-0.16.9/.github/workflows/publish.yml   2020-02-02 
01:00:00.000000000 +0100
@@ -36,3 +36,20 @@
       uses: actions/download-artifact@v4
     - name: Upload packages
       uses: pypa/gh-action-pypi-publish@release/v1
+
+  github-release:
+      name: Create GitHub release
+      needs: pypi-publish
+      runs-on: ubuntu-latest
+      permissions:
+        contents: write
+      steps:
+      - uses: actions/checkout@v4
+      - id: changelog
+        uses: agronholm/release-notes@v1
+        with:
+          path: CHANGELOG.md
+          version_pattern: ^\#\# ([0-9][^*]*)\n
+      - uses: ncipollo/release-action@v1
+        with:
+          body: ${{ steps.changelog.outputs.changelog }}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pycrdt_websocket-0.16.0/.github/workflows/test.yml 
new/pycrdt_websocket-0.16.9/.github/workflows/test.yml
--- old/pycrdt_websocket-0.16.0/.github/workflows/test.yml      2020-02-02 
01:00:00.000000000 +0100
+++ new/pycrdt_websocket-0.16.9/.github/workflows/test.yml      2020-02-02 
01:00:00.000000000 +0100
@@ -35,14 +35,13 @@
       matrix:
         os: [ubuntu-latest, windows-latest, macos-latest]
         python-version:
-          - '3.9'
-          - '3.10'
           - '3.11'
           - '3.12'
           - '3.13'
-          - 'pypy3.9'
-          - 'pypy3.10'
+          - '3.14'
+          - '3.15'
           - 'pypy3.11'
+          - 'pypy3.12'
     defaults:
       run:
         shell: bash -l {0}
@@ -53,13 +52,12 @@
       - uses: actions/setup-python@v5
         with:
           python-version: ${{ matrix.python-version }}
-      - name: Ensure pip >= v25.1
-        run: python -m pip install "pip >= 25.1"
       - name: Install dependencies
         run: |
-          pip install --group test .
-          cd tests; npm install
+          python -m pip install --upgrade pip
+          pip install --group test . && cd tests && npm install
       - name: Check types
+        if: ${{ !startsWith(matrix.python-version, 'pypy') }}
         run: |
           mypy src tests
       - name: Run tests
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pycrdt_websocket-0.16.0/CHANGELOG.md 
new/pycrdt_websocket-0.16.9/CHANGELOG.md
--- old/pycrdt_websocket-0.16.0/CHANGELOG.md    2020-02-02 01:00:00.000000000 
+0100
+++ new/pycrdt_websocket-0.16.9/CHANGELOG.md    2020-02-02 01:00:00.000000000 
+0100
@@ -1,5 +1,46 @@
 # Version history
 
+## 0.16.9
+
+- Clean up empty rooms when serving a client fails, preventing retained 
documents and tasks.
+- Ensure rooms are initialized before reporting that they have started.
+
+## 0.16.8
+
+- Fix send task exception handling.
+
+## 0.16.7
+
+- Fix concurrent clients joining the same room.
+
+## 0.16.6
+
+- Drop Python 3.10 and add Python 3.15.
+- Log each failed server awareness send with its tracaback.
+- Unobserve awareness callback in `YRoom.stop`.
+
+## 0.16.5
+
+- Wait for `start()` to return in `WebsocketServer.stop()`.
+
+## 0.16.4
+
+- Add `ydoc_observed` event.
+
+## 0.16.3
+
+- Bump `pycrdt` to `>=0.14.0,<0.15.0`.
+- Bump `pycrdt-store` to `>=0.1.5,<0.2.0`.
+
+## 0.16.2
+
+- Add message error handler.
+- Add missing exception handler to `YRoom` instantiation in `get_room`.
+
+## 0.16.1
+
+- Bump `pycrdt` to `>=0.13.0,<0.14.0`.
+
 ## 0.16.0
 
 - Allow room to sync with provider.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pycrdt_websocket-0.16.0/PKG-INFO 
new/pycrdt_websocket-0.16.9/PKG-INFO
--- old/pycrdt_websocket-0.16.0/PKG-INFO        2020-02-02 01:00:00.000000000 
+0100
+++ new/pycrdt_websocket-0.16.9/PKG-INFO        2020-02-02 01:00:00.000000000 
+0100
@@ -1,6 +1,6 @@
-Metadata-Version: 2.4
+Metadata-Version: 2.5
 Name: pycrdt-websocket
-Version: 0.16.0
+Version: 0.16.9
 Summary: WebSocket connector for pycrdt
 Project-URL: Homepage, https://github.com/y-crdt/pycrdt-websocket
 Project-URL: Source, https://github.com/y-crdt/pycrdt-websocket
@@ -34,15 +34,15 @@
 Classifier: Intended Audience :: Developers
 Classifier: License :: OSI Approved :: MIT License
 Classifier: Programming Language :: Python
-Classifier: Programming Language :: Python :: 3.9
-Classifier: Programming Language :: Python :: 3.10
 Classifier: Programming Language :: Python :: 3.11
 Classifier: Programming Language :: Python :: 3.12
 Classifier: Programming Language :: Python :: 3.13
-Requires-Python: >=3.9
+Classifier: Programming Language :: Python :: 3.14
+Classifier: Programming Language :: Python :: 3.15
+Requires-Python: >=3.11
 Requires-Dist: anyio<5,>=3.6.2
-Requires-Dist: pycrdt-store<0.2.0,>=0.1.0
-Requires-Dist: pycrdt<0.13.0,>=0.12.16
+Requires-Dist: pycrdt-store<0.2.0,>=0.1.5
+Requires-Dist: pycrdt<0.15.0,>=0.14.13
 Provides-Extra: django
 Requires-Dist: channels; extra == 'django'
 Description-Content-Type: text/markdown
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pycrdt_websocket-0.16.0/pyproject.toml 
new/pycrdt_websocket-0.16.9/pyproject.toml
--- old/pycrdt_websocket-0.16.0/pyproject.toml  2020-02-02 01:00:00.000000000 
+0100
+++ new/pycrdt_websocket-0.16.9/pyproject.toml  2020-02-02 01:00:00.000000000 
+0100
@@ -4,11 +4,11 @@
 
 [project]
 name = "pycrdt-websocket"
-version = "0.16.0"
+version = "0.16.9"
 description = "WebSocket connector for pycrdt"
 license = { file = "LICENSE" }
 readme = "README.md"
-requires-python = ">=3.9"
+requires-python = ">=3.11"
 authors = [
     { name = "David Brochart", email = "[email protected]" },
 ]
@@ -21,16 +21,16 @@
     "Intended Audience :: Developers",
     "License :: OSI Approved :: MIT License",
     "Programming Language :: Python",
-    "Programming Language :: Python :: 3.9",
-    "Programming Language :: Python :: 3.10",
     "Programming Language :: Python :: 3.11",
     "Programming Language :: Python :: 3.12",
     "Programming Language :: Python :: 3.13",
+    "Programming Language :: Python :: 3.14",
+    "Programming Language :: Python :: 3.15",
 ]
 dependencies = [
     "anyio >=3.6.2,<5",
-    "pycrdt >=0.12.16,<0.13.0",
-    "pycrdt-store >=0.1.0,<0.2.0",
+    "pycrdt >=0.14.13,<0.15.0",
+    "pycrdt-store >=0.1.5,<0.2.0",
 ]
 
 [project.optional-dependencies]
@@ -40,7 +40,7 @@
 
 [dependency-groups]
 test = [
-    "mypy !=1.10.0,!=1.10.1",  # see 
https://github.com/python/mypy/issues/17166
+    "mypy !=1.10.0,!=1.10.1; platform_python_implementation != 'PyPy'",  # see 
https://github.com/python/mypy/issues/17166
     "pre-commit",
     "pytest",
     "pytest-timeout",
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/pycrdt_websocket-0.16.0/src/pycrdt/websocket/asgi_server.py 
new/pycrdt_websocket-0.16.9/src/pycrdt/websocket/asgi_server.py
--- old/pycrdt_websocket-0.16.0/src/pycrdt/websocket/asgi_server.py     
2020-02-02 01:00:00.000000000 +0100
+++ new/pycrdt_websocket-0.16.9/src/pycrdt/websocket/asgi_server.py     
2020-02-02 01:00:00.000000000 +0100
@@ -1,8 +1,8 @@
 from __future__ import annotations
 
-from collections.abc import Awaitable
+from collections.abc import Awaitable, Callable
 from inspect import isawaitable
-from typing import Any, Callable
+from typing import Any
 
 from .websocket_server import WebsocketServer
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/pycrdt_websocket-0.16.0/src/pycrdt/websocket/websocket_server.py 
new/pycrdt_websocket-0.16.9/src/pycrdt/websocket/websocket_server.py
--- old/pycrdt_websocket-0.16.0/src/pycrdt/websocket/websocket_server.py        
2020-02-02 01:00:00.000000000 +0100
+++ new/pycrdt_websocket-0.16.9/src/pycrdt/websocket/websocket_server.py        
2020-02-02 01:00:00.000000000 +0100
@@ -1,9 +1,9 @@
 from __future__ import annotations
 
+from collections.abc import Callable
 from contextlib import AsyncExitStack
 from functools import partial
 from logging import Logger, getLogger
-from typing import Callable
 
 from anyio import TASK_STATUS_IGNORED, Event, Lock, create_task_group
 from anyio.abc import TaskGroup, TaskStatus
@@ -20,6 +20,7 @@
     rooms: dict[str, YRoom]
     _started: Event | None = None
     _stopped: Event
+    _start_finished: Event
     _task_group: TaskGroup | None = None
     __start_lock: Lock | None = None
 
@@ -62,6 +63,7 @@
         self.provider_factory = provider_factory
         self.rooms = {}
         self._stopped = Event()
+        self._start_finished = Event()
 
     @property
     def started(self) -> Event:
@@ -71,6 +73,11 @@
         return self._started
 
     @property
+    def running(self) -> bool:
+        """Whether the WebSocket server is running."""
+        return self._task_group is not None
+
+    @property
     def _start_lock(self) -> Lock:
         if self.__start_lock is None:
             self.__start_lock = Lock()
@@ -92,7 +99,10 @@
                 else None
             )
             self.rooms[name] = YRoom(
-                ready=self.rooms_ready, log=self.log, 
provider_factory=provider_factory
+                ready=self.rooms_ready,
+                exception_handler=self.exception_handler,
+                log=self.log,
+                provider_factory=provider_factory,
             )
         room = self.rooms[name]
         await self.start_room(room)
@@ -110,8 +120,12 @@
                 "`await websocket_server.start()`"
             )
 
-        if not room.started.is_set():
-            await self._task_group.start(room.start)
+        if room.started.is_set():
+            return
+
+        async with room._start_room_lock:
+            if not room.started.is_set():
+                await self._task_group.start(room.start)
 
     def get_room_name(self, room: YRoom) -> str:
         """Get the name of a room.
@@ -172,9 +186,12 @@
             async with create_task_group():
                 room = await self.get_room(websocket.path)
                 await self.start_room(room)
-                await room.serve(websocket)
-                if self.auto_clean_rooms and not room.clients:
-                    await self.delete_room(room=room)
+                try:
+                    await room.serve(websocket)
+                finally:
+                    # also when serving failed, so that the room doesn't 
outlive its clients
+                    if self.auto_clean_rooms and not room.clients:
+                        await self.delete_room(room=room)
         except Exception as exception:
             self._handle_exception(exception)
 
@@ -216,6 +233,9 @@
             task_status.started()
             self.started.set()
             assert self._task_group is not None
+            # the context manager awaits the task group on exit, so `stop()` 
has
+            # nothing to wait for
+            self._start_finished.set()
             # wait until stopped
             self._task_group.start_soon(self._stopped.wait)
             return
@@ -224,26 +244,41 @@
             if self._task_group is not None:
                 raise RuntimeError("WebsocketServer already running")
 
-            while True:
-                try:
-                    async with create_task_group() as self._task_group:
-                        if not self.started.is_set():
-                            task_status.started()
-                            self.started.set()
-                        # wait until stopped
-                        self._task_group.start_soon(self._stopped.wait)
-                    return
-                except Exception as exception:
-                    self._handle_exception(exception)
+            try:
+                while True:
+                    try:
+                        async with create_task_group() as self._task_group:
+                            if not self.started.is_set():
+                                task_status.started()
+                                self.started.set()
+                            # wait until stopped
+                            self._task_group.start_soon(self._stopped.wait)
+                        return
+                    except Exception as exception:
+                        self._handle_exception(exception)
+            finally:
+                self._start_finished.set()
 
     async def stop(self) -> None:
-        """Stop the WebSocket server."""
+        """Stop the WebSocket server.
+
+        When the server was started through the lower-level API, this waits 
for the task
+        running `start()` to return, so that the caller can rely on the 
server's tasks
+        being done when `stop()` returns. Wrap the call in 
`anyio.move_on_after()` to
+        bound that wait.
+        """
         if self._task_group is None:
             raise RuntimeError("WebsocketServer not running")
 
         self._stopped.set()
         self._task_group.cancel_scope.cancel()
         self._task_group = None
+        if self._start_finished.is_set():
+            # nothing to wait for: don't checkpoint, as we may be running 
inside the
+            # cancel scope we just cancelled (this is the case when used as an 
async
+            # context manager, which awaits the task group on exit anyway)
+            return
+        await self._start_finished.wait()
 
 
 def exception_logger(exception: Exception, log: Logger) -> bool:
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/pycrdt_websocket-0.16.0/src/pycrdt/websocket/yroom.py 
new/pycrdt_websocket-0.16.9/src/pycrdt/websocket/yroom.py
--- old/pycrdt_websocket-0.16.0/src/pycrdt/websocket/yroom.py   2020-02-02 
01:00:00.000000000 +0100
+++ new/pycrdt_websocket-0.16.9/src/pycrdt/websocket/yroom.py   2020-02-02 
01:00:00.000000000 +0100
@@ -1,11 +1,11 @@
 from __future__ import annotations
 
-from collections.abc import Awaitable
+from collections.abc import Awaitable, Callable
 from contextlib import AsyncExitStack
 from functools import partial
 from inspect import isawaitable
 from logging import Logger, getLogger
-from typing import Any, Callable, Protocol
+from typing import Any, Protocol
 
 from anyio import (
     TASK_STATUS_IGNORED,
@@ -51,7 +51,9 @@
     ydoc: Doc
     ystore: BaseYStore | None
     ready_event: Event
+    _start_room_lock: Lock
     _on_message: Callable[[bytes], Awaitable[bool] | bool] | None
+    _on_message_error: Callable[[Exception, bytes, Channel], Awaitable[bool] | 
bool] | None
     _update_send_stream: MemoryObjectSendStream
     _update_receive_stream: MemoryObjectReceiveStream
     _task_group: TaskGroup | None = None
@@ -59,6 +61,7 @@
     _stopped: Event
     __start_lock: Lock | None = None
     _subscription: Subscription | None = None
+    _awareness_subscription: str | None = None
 
     def __init__(
         self,
@@ -90,22 +93,28 @@
             provider_factory: An optional provider factory used to synchronize 
the room with
                 an external document.
             exception_handler: An optional callback to call when an exception 
is raised, that
-                returns True if the exception was handled.
+                returns True if the exception was handled. Handling exceptions 
does not prevent
+                the room from stopping, but it prevents the exception from 
propagating.
+                Use on_message_error to handle exceptions raised while 
processing messages
+                without stopping the room.
             log: An optional logger.
             ydoc: An optional document for the room (a new one is created 
otherwise).
         """
         self.ydoc = Doc() if ydoc is None else ydoc
         self.ready_event = Event()
+        self.ydoc_observed = Event()
         self.ready = ready
         self.ystore = ystore
         self.provider_factory = provider_factory
         self.log = log or getLogger(__name__)
         self.awareness = Awareness(self.ydoc)
-        self.awareness.observe(self.send_server_awareness)
+        self._awareness_subscription = 
self.awareness.observe(self.send_server_awareness)
         self.clients = set()
         self._on_message = None
+        self._on_message_error = None
         self.exception_handler = exception_handler
         self._stopped = Event()
+        self._start_room_lock = Lock()
         self._provider_stop_event = Event()
 
     @property
@@ -140,6 +149,7 @@
     async def _watch_ready(self):
         await self.ready_event.wait()
         self._subscription = self.ydoc.observe(partial(put_updates, 
self._update_send_stream))
+        self.ydoc_observed.set()
 
     @property
     def on_message(self) -> Callable[[bytes], Awaitable[bool] | bool] | None:
@@ -158,6 +168,32 @@
         """
         self._on_message = value
 
+    @property
+    def on_message_error(
+        self,
+    ) -> Callable[[Exception, bytes, Channel], Awaitable[bool] | bool] | None:
+        """
+        Returns:
+            The optional callback to call when an exception is raised while 
processing
+            a message. The callback receives the exception, the raw message 
bytes,
+            and the channel. If it returns True the error is considered 
handled and
+            processing continues with the next message; otherwise the 
exception propagates.
+        """
+        return self._on_message_error
+
+    @on_message_error.setter
+    def on_message_error(
+        self,
+        value: Callable[[Exception, bytes, Channel], Awaitable[bool] | bool] | 
None,
+    ):
+        """
+        Arguments:
+            value: An optional callback to call when an exception is raised 
while
+            processing a message. If the callback returns True, the error is
+            handled and the message is skipped.
+        """
+        self._on_message_error = value
+
     async def _broadcast_updates(self):
         if self.ystore is not None:
             async with self.ystore.start_lock:
@@ -173,13 +209,8 @@
                 if self.clients:
                     message = create_update_message(update)
                     for client in self.clients:
-                        try:
-                            self.log.debug(
-                                "Sending Y update to client with endpoint: 
%s", client.path
-                            )
-                            self._task_group.start_soon(client.send, message)
-                        except Exception as exception:
-                            self._handle_exception(exception)
+                        self.log.debug("Sending Y update to client with 
endpoint: %s", client.path)
+                        self._task_group.start_soon(self._send_to_client, 
client, message)
                 if self.ystore:
                     try:
                         self._task_group.start_soon(self.ystore.write, update)
@@ -244,9 +275,6 @@
         self,
         task_status: TaskStatus[None],
     ):
-        if not self.started.is_set():
-            task_status.started()
-            self.started.set()
         self._update_send_stream, self._update_receive_stream = 
create_memory_object_stream(
             max_buffer_size=65536
         )
@@ -257,6 +285,11 @@
         await self._task_group.start(self.awareness.start)
         self._task_group.start_soon(self._run_provider)
 
+        # only once the room runs, so that it can be served and stopped right 
away
+        if not self.started.is_set():
+            task_status.started()
+            self.started.set()
+
     async def _run_provider(self):
         if self.provider_factory is not None:
             provider_factory = self.provider_factory(doc=self.ydoc, 
log=self.log)
@@ -276,6 +309,9 @@
         self._task_group = None
         if self._subscription is not None:
             self.ydoc.unobserve(self._subscription)
+        # Break the YRoom -> Awareness -> bound method cycle
+        if self._awareness_subscription is not None:
+            self.awareness.unobserve(self._awareness_subscription)
 
     async def serve(self, channel: Channel):
         """Serve a client.
@@ -294,59 +330,66 @@
                 )
                 await channel.send(sync_message)
                 async for message in channel:
-                    # filter messages (e.g. awareness)
-                    skip = False
-                    if self.on_message:
-                        _skip = self.on_message(message)
-                        skip = await _skip if isawaitable(_skip) else _skip
-                    if skip:
-                        continue
-                    message_type = message[0]
-                    if message_type == YMessageType.SYNC:
-                        # update our internal state in the background
-                        # changes to the internal state are then forwarded to 
all clients
-                        # and stored in the YStore (if any)
-                        self.log.debug(
-                            "Received %s message from endpoint: %s",
-                            YSyncMessageType(message[1]).name,
-                            channel.path,
-                        )
-                        reply = handle_sync_message(message[1:], self.ydoc)
-                        if reply is not None:
+                    try:
+                        # filter messages (e.g. awareness)
+                        skip = False
+                        if self.on_message:
+                            _skip = self.on_message(message)
+                            skip = await _skip if isawaitable(_skip) else _skip
+                        if skip:
+                            continue
+                        message_type = message[0]
+                        if message_type == YMessageType.SYNC:
+                            # update our internal state in the background
+                            # changes to the internal state are then forwarded 
to all clients
+                            # and stored in the YStore (if any)
                             self.log.debug(
-                                "Sending %s message to endpoint: %s",
-                                YSyncMessageType.SYNC_STEP2.name,
+                                "Received %s message from endpoint: %s",
+                                YSyncMessageType(message[1]).name,
                                 channel.path,
                             )
-                            tg.start_soon(channel.send, reply)
-                    elif message_type == YMessageType.AWARENESS:
-                        # forward awareness messages from this client to all 
clients,
-                        # including itself, because it's used to keep the 
connection alive
-                        self.log.debug(
-                            "Received %s message from endpoint: %s",
-                            YMessageType.AWARENESS.name,
-                            channel.path,
-                        )
-
-                        # Check if the message is a client  awareness 
disconnect.
-                        disconnection = 
is_awareness_disconnect_message(message[1:])
-
-                        # Propagate the message to all clients except itself 
if it is a
-                        # disconnection from the client. This avoid an error 
when trying
-                        # to send the message to the disconnected client.
-                        for client in self.clients:
-                            if disconnection and client == channel:
-                                continue
-
+                            reply = handle_sync_message(message[1:], self.ydoc)
+                            if reply is not None:
+                                self.log.debug(
+                                    "Sending %s message to endpoint: %s",
+                                    YSyncMessageType.SYNC_STEP2.name,
+                                    channel.path,
+                                )
+                                tg.start_soon(channel.send, reply)
+                        elif message_type == YMessageType.AWARENESS:
+                            # forward awareness messages from this client to 
all clients,
+                            # including itself, because it's used to keep the 
connection alive
                             self.log.debug(
-                                "Sending Y awareness from client with endpoint 
"
-                                "%s to client with endpoint: %s",
+                                "Received %s message from endpoint: %s",
+                                YMessageType.AWARENESS.name,
                                 channel.path,
-                                client.path,
                             )
-                            tg.start_soon(client.send, message)
-                        # apply awareness update to the server's awareness
-                        
self.awareness.apply_awareness_update(read_message(message[1:]), self)
+
+                            # Check if the message is a client  awareness 
disconnect.
+                            disconnection = 
is_awareness_disconnect_message(message[1:])
+
+                            # Propagate the message to all clients except 
itself if it is a
+                            # disconnection from the client. This avoid an 
error when trying
+                            # to send the message to the disconnected client.
+                            for client in self.clients:
+                                if disconnection and client == channel:
+                                    continue
+
+                                self.log.debug(
+                                    "Sending Y awareness from client with 
endpoint "
+                                    "%s to client with endpoint: %s",
+                                    channel.path,
+                                    client.path,
+                                )
+                                tg.start_soon(self._send_to_client, client, 
message)
+                            # apply awareness update to the server's awareness
+                            
self.awareness.apply_awareness_update(read_message(message[1:]), self)
+                    except Exception as exc:
+                        if self._on_message_error is not None:
+                            _handled = self._on_message_error(exc, message, 
channel)
+                            handled = await _handled if isawaitable(_handled) 
else _handled
+                            if handled:
+                                continue
         except Exception as exception:
             self._handle_exception(exception)
         finally:
@@ -373,13 +416,29 @@
             self.log.error("Cannot broadcast server awareness: YRoom not 
started")
 
     async def _send_server_awareness(self, state: bytes) -> None:
+        async with create_task_group() as tg:
+            for client in self.clients:
+                self.log.debug(
+                    "Sending awareness from server to client with endpoint: 
%s",
+                    client.path,
+                )
+                tg.start_soon(self._send_server_awareness_to_client, client, 
state)
+
+    async def _send_server_awareness_to_client(self, client: Channel, state: 
bytes) -> None:
         try:
-            async with create_task_group() as tg:
-                for client in self.clients:
-                    self.log.debug(
-                        "Sending awareness from server to client with 
endpoint: %s",
-                        client.path,
-                    )
-                    tg.start_soon(client.send, state)
-        except Exception as e:
-            self.log.error("Error while broadcasting awareness changes: %s", e)
+            await client.send(state)
+        except Exception:
+            self.log.exception(
+                "Error while broadcasting awareness changes to client with 
endpoint: %s",
+                client.path,
+            )
+
+    async def _send_to_client(self, client: Channel, message: bytes) -> None:
+        # A failed broadcast must not affect the room or the other clients. 
Sends required
+        # for a client's own sync session propagate errors so that its session 
can end.
+        try:
+            await client.send(message)
+        except Exception:
+            self.log.exception(
+                "Error while sending message to client with endpoint: %s", 
client.path
+            )
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pycrdt_websocket-0.16.0/tests/test_asgi.py 
new/pycrdt_websocket-0.16.9/tests/test_asgi.py
--- old/pycrdt_websocket-0.16.0/tests/test_asgi.py      2020-02-02 
01:00:00.000000000 +0100
+++ new/pycrdt_websocket-0.16.9/tests/test_asgi.py      2020-02-02 
01:00:00.000000000 +0100
@@ -1,11 +1,45 @@
 import pytest
-from anyio import sleep
+from anyio import fail_after, sleep
 
 from pycrdt import Map
+from pycrdt.websocket import ASGIServer, WebsocketServer, YRoom
 
 pytestmark = pytest.mark.anyio
 
 
+async def test_asgi_deletes_room_after_text_frame():
+    events = iter(
+        [
+            {"type": "websocket.connect"},
+            # Uvicorn omits the bytes key for text frames, as permitted by 
ASGI.
+            {"type": "websocket.receive", "text": "hello"},
+        ]
+    )
+    sent: list[dict] = []
+    rooms: list[YRoom] = []
+
+    async def receive():
+        return next(events)
+
+    async def send(message):
+        sent.append(message)
+        if message["type"] == "websocket.send":
+            rooms.append(server.rooms["/room"])
+
+    async with WebsocketServer() as server:
+        app = ASGIServer(server)
+        with fail_after(5):
+            with pytest.raises(ExceptionGroup) as excinfo:
+                await app({"type": "websocket", "path": "/room"}, receive, 
send)
+
+        assert excinfo.group_contains(KeyError, match="bytes")
+        assert sent[0] == {"type": "websocket.accept"}
+        assert len(rooms) == 1  # The room sent its initial binary sync 
message.
+        assert not rooms[0].clients
+        assert rooms[0]._task_group is None
+        assert server.rooms == {}
+
+
 @pytest.mark.parametrize("yws_server", [{"auto_clean_rooms": False}], 
indirect=True)
 @pytest.mark.parametrize("yws_providers", [2], indirect=True)
 async def test_asgi(yws_server, yws_providers):
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pycrdt_websocket-0.16.0/tests/test_server.py 
new/pycrdt_websocket-0.16.9/tests/test_server.py
--- old/pycrdt_websocket-0.16.0/tests/test_server.py    2020-02-02 
01:00:00.000000000 +0100
+++ new/pycrdt_websocket-0.16.9/tests/test_server.py    2020-02-02 
01:00:00.000000000 +0100
@@ -1,9 +1,17 @@
 import pytest
-from anyio import fail_after, sleep
+from anyio import (
+    CancelScope,
+    Event,
+    create_task_group,
+    fail_after,
+    move_on_after,
+    sleep,
+    sleep_forever,
+)
 from utils import create_yws_provider, create_yws_server, get_unused_tcp_port
 
-from pycrdt import Text
-from pycrdt.websocket import exception_logger
+from pycrdt import Doc, Text, create_sync_message
+from pycrdt.websocket import WebsocketServer, YRoom, exception_logger
 
 pytestmark = pytest.mark.anyio
 
@@ -58,3 +66,218 @@
                     break
 
     assert str(text2) == "Hello"
+
+
+async def test_stop_waits_for_start_to_return():
+    # A task that is slow to unwind, so that the moment `stop()` returns is
+    # observably distinct from the moment `start()` returns.
+    async def slow_to_cancel():
+        try:
+            await sleep_forever()
+        finally:
+            with CancelScope(shield=True):
+                await sleep(0.1)
+
+    server = WebsocketServer()
+    start_returned = Event()
+
+    async def run_server():
+        await server.start()
+        start_returned.set()
+
+    async with create_task_group() as tg:
+        tg.start_soon(run_server)
+        await server.started.wait()
+        server._task_group.start_soon(slow_to_cancel)
+        await sleep(0.1)
+        await server.stop()
+        assert start_returned.is_set()
+
+
+async def test_stop_can_be_bounded_by_the_caller():
+    # A task that cannot be cancelled, so that `stop()` has something to wait 
for.
+    # The caller must be able to give up on it rather than block forever.
+    async def never_cancels():
+        with CancelScope(shield=True):
+            await sleep(0.5)
+
+    server = WebsocketServer()
+
+    async with create_task_group() as tg:
+        tg.start_soon(server.start)
+        await server.started.wait()
+        server._task_group.start_soon(never_cancels)
+        await sleep(0.1)
+        with fail_after(0.3):
+            with move_on_after(0.1):
+                await server.stop()
+
+
+async def test_concurrent_get_room_starts_room_once():
+    async with WebsocketServer() as server:
+        rooms = []
+
+        async def get_room():
+            rooms.append(await server.get_room("/room"))
+
+        with fail_after(1):
+            async with create_task_group() as tg:
+                tg.start_soon(get_room)
+                tg.start_soon(get_room)
+
+        assert len(rooms) == 2
+        assert rooms[0] is rooms[1]
+
+
+async def test_room_startup_does_not_block_other_rooms():
+    startup_entered = Event()
+    allow_startup = Event()
+
+    class SlowRoom(YRoom):
+        async def start(self, *, task_status):
+            startup_entered.set()
+            await allow_startup.wait()
+            await super().start(task_status=task_status)
+
+    with fail_after(1):
+        async with WebsocketServer() as server:
+            slow_room = SlowRoom()
+            server.rooms["/slow"] = slow_room
+
+            async with create_task_group() as tg:
+                tg.start_soon(server.get_room, "/slow")
+                await startup_entered.wait()
+
+                other_room = await server.get_room("/other")
+                assert other_room.started.is_set()
+                assert not slow_room.started.is_set()
+
+                allow_startup.set()
+
+
+async def test_context_manager_stop_does_not_stall():
+    # The context manager awaits the task group itself on exit, so `stop()` has
+    # nothing to wait for and must not block on its way out.
+    with fail_after(1):
+        async with WebsocketServer():
+            pass
+
+
+class FakeChannel:
+    def __init__(
+        self,
+        path: str,
+        messages: list[bytes],
+        send_error: Exception | None = None,
+        receive_error: Exception | None = None,
+    ) -> None:
+        self.path = path
+        self.messages = messages
+        self.send_error = send_error
+        self.receive_error = receive_error
+
+    def __aiter__(self):
+        return self
+
+    async def __anext__(self) -> bytes:
+        if self.messages:
+            return self.messages.pop(0)
+        if self.receive_error is not None:
+            raise self.receive_error
+        # the client disconnected
+        raise StopAsyncIteration
+
+    async def send(self, message: bytes) -> None:
+        if self.send_error is not None:
+            raise self.send_error
+
+
+async def test_server_deletes_room_after_error():
+    # ASGIWebsocket raises KeyError when the client sends a text frame
+    channel = FakeChannel("/room", [], receive_error=KeyError("bytes"))
+    async with WebsocketServer() as server:
+        with pytest.raises(ExceptionGroup) as excinfo:
+            await server.serve(channel)
+
+        assert excinfo.group_contains(KeyError)
+        assert server.rooms == {}
+
+
[email protected]("fail_on_send", [1, 2], ids=["handshake", 
"sync_reply"])
+async def test_server_client_send_error(fail_on_send):
+    error = RuntimeError("foo")
+
+    class FailingChannel(FakeChannel):
+        sends = 0
+
+        async def send(self, message: bytes) -> None:
+            self.sends += 1
+            if self.sends == fail_on_send:
+                raise error
+
+        async def __anext__(self) -> bytes:
+            # A send failure need not be followed by a receive-side disconnect.
+            if not self.messages:
+                await sleep_forever()
+            return self.messages.pop(0)
+
+    channel = FailingChannel("/room", [create_sync_message(Doc())])
+    async with WebsocketServer() as server:
+        room = await server.get_room(channel.path)
+        with fail_after(5):
+            with pytest.raises(ExceptionGroup) as excinfo:
+                await server.serve(channel)
+
+        assert excinfo.group_contains(RuntimeError, match="foo")
+        assert channel.sends == fail_on_send
+        assert not room.clients
+        assert server.rooms == {}
+        assert room._task_group is None
+
+
+class IdleChannel:
+    """A client that stays connected until it leaves."""
+
+    def __init__(self, path: str) -> None:
+        self.path = path
+        self.served = Event()
+        self.left = Event()
+
+    def __aiter__(self):
+        return self
+
+    async def __anext__(self) -> bytes:
+        await self.left.wait()
+        # the client disconnected
+        raise StopAsyncIteration
+
+    async def send(self, message: bytes) -> None:
+        # the room starts serving a client by sending it SYNC_STEP1
+        self.served.set()
+
+    async def wait_until_served(self) -> None:
+        with fail_after(5):
+            await self.served.wait()
+
+
+async def test_client_joins_room_as_its_last_client_leaves():
+    client1 = IdleChannel("/room")
+    client2 = IdleChannel("/room")
+    client3 = IdleChannel("/room")
+    async with WebsocketServer() as server:
+        async with create_task_group() as tg:
+            tg.start_soon(server.serve, client1)
+            await client1.wait_until_served()
+            # client2 joins the room as client1, its only client, leaves it
+            tg.start_soon(server.serve, client2)
+            client1.left.set()
+            await client2.wait_until_served()
+            tg.start_soon(server.serve, client3)
+            await client3.wait_until_served()
+
+            # client2 isn't left alone in a deleted room, apart from the 
clients joining after it
+            assert server.rooms["/room"].clients == {client2, client3}
+            client2.left.set()
+            client3.left.set()
+
+        assert server.rooms == {}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/pycrdt_websocket-0.16.0/tests/test_yroom.py 
new/pycrdt_websocket-0.16.9/tests/test_yroom.py
--- old/pycrdt_websocket-0.16.0/tests/test_yroom.py     2020-02-02 
01:00:00.000000000 +0100
+++ new/pycrdt_websocket-0.16.9/tests/test_yroom.py     2020-02-02 
01:00:00.000000000 +0100
@@ -1,9 +1,13 @@
+import gc
+import weakref
+
 import pytest
-from anyio import TASK_STATUS_IGNORED, create_task_group, sleep
+from anyio import TASK_STATUS_IGNORED, Event, create_task_group, fail_after, 
sleep
 from anyio.abc import TaskStatus
-from utils import Websocket
+from anyio.lowlevel import checkpoint
+from utils import StartStopContextManager, Websocket, connected_websockets
 
-from pycrdt import Map
+from pycrdt import Awareness, Doc, Map, create_awareness_message
 from pycrdt.websocket import exception_logger
 from pycrdt.websocket.yroom import YRoom
 
@@ -56,3 +60,133 @@
     assert yroom._task_group is not None
     assert not yroom._task_group.cancel_scope.cancel_called
     await yroom.stop()
+
+
+class FakeClient:
+    def __init__(self, path: str, error: Exception | None = None) -> None:
+        self.path = path
+        self.error = error
+        self.messages: list[bytes] = []
+        self.send_finished = Event()
+
+    async def send(self, message: bytes) -> None:
+        try:
+            if self.error is not None:
+                raise self.error
+            # Give failing sends an opportunity to interrupt this send.
+            await checkpoint()
+            self.messages.append(message)
+        finally:
+            self.send_finished.set()
+
+    async def wait_for_send(self) -> None:
+        with fail_after(5):
+            await self.send_finished.wait()
+        self.send_finished = Event()
+
+
+async def test_yroom_server_awareness_send_error(yroom, caplog):
+    client1 = FakeClient("client1", RuntimeError("foo"))
+    client2 = FakeClient("client2", ValueError("bar"))
+    client3 = FakeClient("client3")
+    yroom.clients.update({client1, client2, client3})
+    await yroom._send_server_awareness(b"awareness")
+
+    records = [record for record in caplog.records if record.levelname == 
"ERROR"]
+    assert len(records) == 2
+    errors = {
+        record.getMessage(): record.exc_info[1] if record.exc_info else None 
for record in records
+    }
+    message = "Error while broadcasting awareness changes to client with 
endpoint: {}"
+    assert errors == {
+        message.format("client1"): client1.error,
+        message.format("client2"): client2.error,
+    }
+    # the other clients still get the awareness update
+    assert client3.messages == [b"awareness"]
+
+
+async def test_yroom_update_send_error(yroom_api, caplog):
+    client1 = FakeClient("client1", RuntimeError("foo"))
+    client2 = FakeClient("client2")
+
+    # don't use the yroom fixture here, because if it fails, it may hang on 
the trio test
+    room = YRoom()
+    service = StartStopContextManager(room) if yroom_api == "yroom_start_stop" 
else room
+    async with service:
+        room.clients.update({client1, client2})
+        await room.ydoc_observed.wait()
+        room.ydoc["map"] = ymap = Map()
+        ymap["key1"] = "value1"
+        await client1.wait_for_send()
+        await client2.wait_for_send()
+        ymap["key2"] = "value2"
+        await client1.wait_for_send()
+        await client2.wait_for_send()
+
+    errors = [
+        (record.getMessage(), record.exc_info[1] if record.exc_info else None)
+        for record in caplog.records
+        if record.levelname == "ERROR"
+    ]
+    message = "Error while sending message to client with endpoint: client1"
+    assert errors == [(message, client1.error), (message, client1.error)]
+    # the room keeps broadcasting the updates to the other clients
+    assert len(client2.messages) == 2
+
+
+async def test_yroom_client_awareness_send_error(yroom, caplog):
+    client1 = FakeClient("client1", RuntimeError("foo"))
+    client2 = FakeClient("client2")
+    yroom.clients.update({client1, client2})
+    doc = Doc()
+    awareness = Awareness(doc)
+    awareness.set_local_state({"cursor": 1})
+    message = 
create_awareness_message(awareness.encode_awareness_update([doc.client_id]))
+    server_websocket, client_websocket = connected_websockets()
+    sender = Websocket(server_websocket, "sender")
+
+    async with create_task_group() as tg:
+        tg.start_soon(yroom.serve, sender)
+        await client_websocket.send_bytes(message)
+        await client1.wait_for_send()
+        await client2.wait_for_send()
+
+        errors = [
+            (record.getMessage(), record.exc_info[1] if record.exc_info else 
None)
+            for record in caplog.records
+            if record.levelname == "ERROR"
+        ]
+        assert errors == [
+            ("Error while sending message to client with endpoint: client1", 
client1.error)
+        ]
+        # the sender stays connected, and the other clients still get its 
awareness
+        assert sender in yroom.clients
+        assert client2.messages == [message]
+        tg.cancel_scope.cancel()
+
+
+async def test_yroom_stop_releases_awareness_callback(yroom_api):
+    async def run_room():
+        room = YRoom()
+        room_ref = weakref.ref(room)
+        awareness = room.awareness
+        service = StartStopContextManager(room) if yroom_api == 
"yroom_start_stop" else room
+        async with service:
+            await room.ydoc_observed.wait()
+        return room_ref, awareness
+
+    room_ref, awareness = await run_room()
+    # Collect completed task cycles; PyPy may need a second collection.
+    gc.collect()
+    gc.collect()
+    # A registered bound callback would keep the stopped room alive through 
awareness.
+    assert room_ref() is None
+    assert awareness is not None
+
+
+async def test_yroom_stops_right_after_starting():
+    room = YRoom()
+    async with create_task_group() as tg:
+        await tg.start(room.start)
+        await room.stop()

Reply via email to