diff --git a/jupyter_collaboration/rooms.py b/jupyter_collaboration/rooms.py index 77b22ef7..f92a5727 100644 --- a/jupyter_collaboration/rooms.py +++ b/jupyter_collaboration/rooms.py @@ -103,9 +103,10 @@ async def initialize(self) -> None: # try to apply Y updates from the YStore for this document read_from_source = True if self.ystore is not None: - if not self.ystore.started.is_set(): - self.create_task(self.ystore.start()) - await self.ystore.started.wait() + async with self.ystore.start_lock: + if not self.ystore.started.is_set(): + self.create_task(self.ystore.start()) + await self.ystore.started.wait() try: await self.ystore.apply_updates(self.ydoc) self._emit(